0% found this document useful (0 votes)
3 views

exp_5

Uploaded by

viji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

exp_5

Uploaded by

viji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

dP (t)

1. Solve : dt
= r.

from sympy import *


init_printing ()

t , r = symbols ( 't , r ') # Define the symbols


P = Function ( 'P ') ( t ) # define function
C1 = Symbol ( ' C1 ')

print ( " \ nDifferential Equation " )


DE1 = Derivative (P , t , 1 ) - r # define the differeentail equation
display ( DE1 )

# General solution
print ( " \ nGeneral Solution " )

GS1 = dsolve ( DE1 ) # Solve the differentail equation


display ( GS1 ) # Display the solution

print ( " \ nParticular Solution " )


PS1 = GS1 . subs ( { C1 : 2 } ) # substitute the value of the conastant
display ( PS1 )

dy
2: Solve: dx
+ tanx − y 3 secx = 0.

from sympy import *

x , y = symbols ( 'x , y ')


y = Function ( " y " ) ( x )

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.

from sympy import *

x , y = symbols ( 'x , y ')


y = Function ( " y " ) ( x )
y1 = Derivative (y , x )
z1 = dsolve ( Eq ( x ** 3 * y1 - x ** 2 * y + y ** 4 * cos ( x ) ,0 ) ,y )
display ( z1 )

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

# values for time


t = np . linspace (0 , 20 )

# 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

You might also like