Created
January 27, 2021 20:19
-
-
Save lefuturiste/16bb233d58f53dc7632119eaefdcd004 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from math import exp, sqrt, log, cos, sin, pi | |
import numpy as np | |
import matplotlib.pyplot as plt | |
plt.rcParams["savefig.dpi"] = 500 | |
## Exercice 3 | |
def suite(f, u, n, a, b, c, d): | |
x = [u, u] | |
y = [0, f(u)] | |
for i in range(1, n+1): | |
u = f(u) | |
x = x+[u, u] | |
y = y+[u, f(u)] | |
plt.plot(x, y, 'r-', lw=2) # la ligne brisé | |
plt.plot([a,b],[0,0],'k') #abscisses | |
plt.plot([0,0],[c,d],'k') #ordonnées | |
plt.plot( | |
[min(a, c), min(b, d)], | |
[min(a,c), min(b, d)] | |
) # 1ere bissectrice | |
t = np.arange(a, b, 0.01) | |
T = np.vectorize(f)(t) | |
plt.plot(t, T, 'b-', lw=2) | |
plt.xlim(a, b) | |
plt.ylim(c, d) | |
#suite(np.cos, 1.4, 10, 0, 1.6, 0, 1) | |
#suite(lambda x: np.sin(x)/2, 1, 10, 0, 1.6, 0, 1) | |
#suite(lambda x: 1/4 * (x+1)**2, -1.9, 10, -2, 2, 0, 2) | |
#suite(lambda x: 1/4 * (x+1)**2, 1.5, 9, 0, 7, 0, 12) | |
## Exercice 4 | |
def superPlot(xFun, yFun, tMin, tMax): | |
t = np.arange(tMin, tMax, 0.01) | |
x = np.vectorize(xFun)(t) | |
y = np.vectorize(yFun)(t) | |
plt.plot(x, y) | |
plt.subplot(2, 2, 1) | |
superPlot( | |
lambda t: sin(t)**3, | |
lambda t: cos(t)-cos(t)**4, | |
0, 2*pi | |
) | |
plt.subplot(2, 2, 2) | |
superPlot( | |
lambda t: 3*cos(t)+2*cos(3*t), | |
lambda t: 3*sin(t)-2*sin(3*t), | |
0, 2*pi | |
) | |
plt.subplot(2, 2, 3) | |
superPlot( | |
lambda t: cos(t)*(1-2*cos(t)), | |
lambda t: sin(t)*(1-2*cos(t)), | |
0, 2*pi | |
) | |
plt.subplot(2, 2, 4) | |
superPlot( | |
lambda t: cos(t)+sqrt(8)*cos(t/2), | |
sin, | |
0, 4*pi | |
) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment