Of course! I just provide the exact solution here to show how accurate the method is. As you might have noticed, the exact solution was not used in any of the calculations using in the Runge Kutta. It was just used to create the plot to compare the Runge Kutta against. Hope this helps
Hi Sir, I try I've tried running the code in PyCharm, but I'm not sure if it's as shown, would you have any idea what error I'm making. Thanks for sharing. import math import matplotlib.pyplot as plt #Functions - Funções Sgma_y = lambda x,y: math.sin(x)**2*y f = lambda x: 2*math.exp{0.5*(x*math.sin(x)*math.cos(x))} #Visual (zot om Code inicial) print('x\t\t y \t\t f(x)'); print('xf\t xf'x {x,y, f(x)}) x_plot* []; y_Rx4.apperd(y); y_analytical.apperd(f(x)) * [] #Rx4 method for i in range(1, n+1): #futer's Method k1 = Sgma_y(x,y) k2 = Sgma_y(x*h/2, y * k1 * h/2) k3 = Sgma_y(x*h/2, y * k2*h/2) k4 = Sgma_y(x*h, y * k3*h) #Calculate new y estimation y* y + 1/ 6 * (k1 * 2 * k2 * 2 * k3 * k4) * h #increase x by step size to calculate next y estimate x = x + h print('Xf\t Xf \t Xf'X (x, y, f(x))) #Visualization Code x_plot.append(x); y_Kx4.append(y); y_analytical.append(f(x)) plt.plot(x_plot,y_kx4,'ro',x_plot,y_analytical) plt.xlabel('x');plt.ylabel('y') plt.legend(['kx4','Analytical'])
you haven't mentioned the question( i mean of the differential equation) , it will lead us to understand more efficiently.
What are the functions?
Bro, can you tell me what was the function in the problem? And what is “f” and “dy”
pleas zoom the code
Can't we do this without knowing the exact solution?
Of course! I just provide the exact solution here to show how accurate the method is. As you might have noticed, the exact solution was not used in any of the calculations using in the Runge Kutta. It was just used to create the plot to compare the Runge Kutta against. Hope this helps
@@shamselfouly yes I got it 😊
Could you send me the code please?
الرجاء وضع الكود في شكل pdf
CODE PLCELSE
Hi Sir, I try
I've tried running the code in PyCharm, but I'm not sure if it's as shown, would you have any idea what error I'm making. Thanks for sharing.
import math
import matplotlib.pyplot as plt
#Functions - Funções
Sgma_y = lambda x,y: math.sin(x)**2*y
f = lambda x: 2*math.exp{0.5*(x*math.sin(x)*math.cos(x))}
#Visual (zot om Code inicial)
print('x\t\t y \t\t f(x)'); print('xf\t xf'x {x,y, f(x)})
x_plot* []; y_Rx4.apperd(y); y_analytical.apperd(f(x)) * []
#Rx4 method
for i in range(1, n+1):
#futer's Method
k1 = Sgma_y(x,y)
k2 = Sgma_y(x*h/2, y * k1 * h/2)
k3 = Sgma_y(x*h/2, y * k2*h/2)
k4 = Sgma_y(x*h, y * k3*h)
#Calculate new y estimation
y* y + 1/ 6 * (k1 * 2 * k2 * 2 * k3 * k4) * h
#increase x by step size to calculate next y estimate
x = x + h
print('Xf\t Xf \t Xf'X (x, y, f(x)))
#Visualization Code
x_plot.append(x); y_Kx4.append(y); y_analytical.append(f(x))
plt.plot(x_plot,y_kx4,'ro',x_plot,y_analytical)
plt.xlabel('x');plt.ylabel('y')
plt.legend(['kx4','Analytical'])