Category : numerical-methods

Following is my attempt to create a function to differentiate multivariable functions, but as you see it only seems to be able to differentiate with respect to the first positional argument (namely x). How can I extend this to be able to take partial derivatives with respect to y and z? def firstderivative(func,x,*args): return((func(x+0.001,*args)-func(x-0.001,*args))/0.002) def ..

Read more

I’m trying to implement a RK4 for a equation that is given by x'(t)=0.4x(t)-0.018x(t)y(t); x(0)=30 y'(t)=-0.8y(t)+0.023x(t)y(t); y(0)=4 and i got this code def f(x,y,t): return 0.4*x*t-0.018*x*t*y def rk4(x0,y0,xn,n): h = (xn-x0)/n print(‘n——–SOLUTION——–‘) print(‘————————-‘) print(‘x0ty0tyn’) print(‘————————-‘) for i in range(n): k1 = h * (f(x0, y0)) k2 = h * (f((x0+h/2), (y0+k1/2))) k3 = h * ..

Read more