Question: PYTHON QUESTION: there is 2 different solving methods for our one differential equation.I want to compare these 2 solving methods on the same graphic. I

PYTHON QUESTION:

there is 2 different solving methods for our one differential equation.I want to compare these 2 solving methods on the same graphic. I wrote two different codes for each solving method. Please rearrenge these codes and make them one code. and plot and compare x-y graphics on the same window by plt.plot() and plt.show() functions...

CODE NUMBER1 for RungaKutta2:

from math import* from pylab import*

x1=[] y1=[] def rkutta(f,x0,y0): h=0.1 xs=8 a2=2/3 p=3/4 q=3/4 while x0<=xs: x=x0+h k1=f(x0,y0) k2=f(x0+p*h,y0+q*h*k1) y=y0+h*(a1*k1+a2*k2) x0=x y0=y return y

def f1(x,y): return(tan(radius(x))+exp(0.5*y))

rkutta(f1,1,2) subplot(211) plot(x1,y1) grid() show()

CODE NUMBER 2 RungaKutta4:

from math import* from pylab import*

x1=[] y1=[] def rkutta(f,x0,y0): h=0.1 xs=8 while x0<=xs: x=x0+h k1=f(x0,y0) k2=f(x0+h/2,y0+(h/2)*k1) k3=f(x0+h/2,y0+(h/2)*k2) k4=f(x0+h,y0+h*k3) y=y0+(h/6)*(k1+2*2+2*k3*k4) x0=x y0=y return y

def f1(x,y): return(tan(radius(x))+exp(0.5*y))

rkutta(f1,1,2) subplot(212) plot(x1,y1) grid() show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!