Skip to content

Instantly share code, notes, and snippets.

View mick001's full-sized avatar

Michy mick001

View GitHub Profile
import java.util.Scanner;
import java.util.Random;
public class SentenceGeneratorMain
{
public static void main(String[] args)
{
//Variables declaration and initialization
Scanner reader = new Scanner(System.in);
String input = new String();
# >>>
# Taylor expansion at n=1 x
# Taylor expansion at n=3 -x**3/6 + x
# Taylor expansion at n=5 x**5/120 - x**3/6 + x
# Taylor expansion at n=7 -x**7/5040 + x**5/120 - x**3/6 + x
# Taylor expansion at n=9 x**9/362880 - x**7/5040 + x**5/120 - x**3/6 + x
import sympy as sy
import numpy as np
from sympy.functions import sin,cos
import matplotlib.pyplot as plt
plt.style.use("ggplot")
# Define the variable and the function to approximate
x = sy.Symbol('x')
f = sin(x)
# Plot results
def plot():
x_lims = [-5,5]
x1 = np.linspace(x_lims[0],x_lims[1],800)
y1 = []
# Approximate up until 10 starting from 1 and using steps of 2
for j in range(1,10,2):
func = taylor(f,0,j)
print('Taylor expansion at n='+str(j),func)
for k in x1:
% Solid of revolution %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
syms x
syms y
% Cone height
h = 10;
% Our generator function
y1 = @(x) 1/2*x;
% Output
% v =
%
% (250*pi)/3
# Solid of rotation: a cone
#-------------------------------------------------------------------------------
# Our function to generate the solid of rotation
foo <- function(x)
{
return(0.5*x)
}
# This function integrates f^2 over the given [a,b] interval
# Output
# >>> ================================ RESTART ================================
# >>>
# Actual area: 5208.333333333333
#
# Approximating using rectangular rule...
# Percentage error: -0.0104123281966 %
# Approximation: (5207.7910245730936, -0.010412328196596356)
#
# Approximating using trapezoidal rule...
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('ggplot')
# Initial function given
def f(x):
return x**2
# Definite integral of the function from a to b
@mick001
mick001 / crankshaft.py
Created August 29, 2015 11:08
Crankshaft connecting rod and piston mechanism simulation with Python. Full article at http://www.firsttimeprogrammer.blogspot.com/2015/02/crankshaft-connecting-rod-and-piston.html
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import visual as v
import numpy as np
import time
plt.style.use('ggplot')
class My_mechanism(object):