This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# >>> | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Solid of revolution % | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
syms x | |
syms y | |
% Cone height | |
h = 10; | |
% Our generator function | |
y1 = @(x) 1/2*x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Output | |
% v = | |
% | |
% (250*pi)/3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Output | |
# >>> ================================ RESTART ================================ | |
# >>> | |
# Actual area: 5208.333333333333 | |
# | |
# Approximating using rectangular rule... | |
# Percentage error: -0.0104123281966 % | |
# Approximation: (5207.7910245730936, -0.010412328196596356) | |
# | |
# Approximating using trapezoidal rule... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | |