@@ -74,26 +74,25 @@ Encontre uma solução numérica para a equação diferencial com condição ini
7474``` {code-cell} ipython3
7575%matplotlib widget
7676import numpy as np
77- from scipy.integrate import odeint
77+ from scipy.integrate import solve_ivp
7878import matplotlib.pyplot as plt
7979
80- # function that returns dy/dt
81- def model(y,t):
82- dydt = -y + 1.0
83- return dydt
80+ def exponential_decay(t, y): return -0.5 * y
8481
85- # initial condition
86- y0 = 0
82+ # solve_ivp(fun, t_span, y0)
83+ sol = solve_ivp(exponential_decay, [0, 10], [2, 4, 8])
8784
88- # time points
89- t = np.linspace(0,5)
85+ print(sol.t)
86+ ```
9087
91- # solve ODE
92- y = odeint(model,y0,t)
88+ ``` {code-cell} ipython3
89+ print(sol.y)
90+ ```
9391
92+ ``` {code-cell} ipython3
9493# plot results
9594fig = plt.figure()
96- plt.plot(t,y )
95+ plt.plot(sol.t, sol.y.T )
9796plt.xlabel('time')
9897plt.ylabel('y(t)')
9998plt.show()
@@ -118,15 +117,14 @@ y = x + 5*np.random.rand(10) - 6*np.random.rand(10)
118117f = interp1d(x, y)
119118
120119# Gráfico
121- fig = plt.figure ()
120+ fig, ax = plt.subplots ()
122121t = np.linspace(0, 9, 50)
123- plt.title('Exemplo: ajuste de curvas')
124- plt.plot(x, y, 'r*')
125- plt.plot(t, a_linear*t+b_linear,'g')
126- plt.plot(t, a_quad*t**2+b_quad*t+c_quad, 'm')
127- plt.plot(t, f(t), 'b')
128- plt.legend(['linear', 'quadrático', 'interpolação'])
129- plt.show();
122+ ax.set_title('Exemplo: ajuste de curvas')
123+ ax.plot(x, y, 'r*')
124+ ax.plot(t, a_linear*t+b_linear,'g')
125+ ax.plot(t, a_quad*t**2+b_quad*t+c_quad, 'm')
126+ ax.plot(t, f(t), 'b')
127+ ax.legend(['linear', 'quadrático', 'interpolação'])
130128```
131129
132130### Exemplo: Teste de hipótese estatística
0 commit comments