Tema SSD

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import numpy as np

from scipy.integrate import odeint


import matplotlib.pyplot as plt

# function that returns dy/dt


def model(y,x):
dydx = (y + np.sqrt(x*y))/x
return dydx

# initial condition
y1 = 1

# time points
x = np.linspace(1, 10)

# solve ODE
y = odeint(model,y1,x)

# plot results
plt.plot(x,y)
plt.xlabel('time')
plt.ylabel('y(x)')
plt.show()

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# function that returns dy/dt


def model(y,x):
dydx = (y + np.sqrt(x*y))/x
return dydx

# initial condition
y1 = 1

# time points
x = np.linspace(1, 10)

# solve ODE
y = odeint(model,y1,x)

def solexact(x):
return (x/4.0) * np.power(np.log(np.absolute(x)), x)

# plot results
plt.plot(x,y,'b',x,solexact(x),'r*')
plt.xlabel('time')
plt.ylabel('y(x)')
plt.show()

You might also like