exp_5
exp_5
1. Solve : dt
= r.
# General solution
print ( " \ nGeneral Solution " )
dy
2: Solve: dx
+ tanx − y 3 secx = 0.
y1 = Derivative (y , x )
z1 = dsolve ( Eq ( y1 + y * tan ( x ) - y ** 3 * sec ( x ) ) ,y )
display ( z1 )
dy
3: Solve: x3 dx − x2 y + y 4 cosx = 0.
37
dy
4. Solve dt
= −ky with parameter k = 0.3 and y(0) = 5.
import numpy as np
from scipy . integrate import odeint
import matplotlib . pyplot as plt
# Function returns dy / dt
def model (y , t ) :
k=0.3
# dydt = - k * y
return - k * y
# initial condition
y0 = 5
# solve ODE
y = odeint ( model , y0 , t )
plt . plot (t , y )
plt . title ( ' Solution of dy / dt = - ky ; k = 0 .3 , y ( 0 ) = 5 ')
plt . xlabel ( ' time ')
plt . ylabel ( 'y ( t ) ')
plt . show ()
38