y=zeros(1,length(x)); z=zeros(1,length(x)); y(1)=0; z(1)=0; Fx1= @(x2)(3)*x2; Gx2=@(x1)(1/3)*x1; for i=2:(length(x)-1) k1=Fx1(x(i),y(i)); g1=Gx2(x(i),y(i)); k2=Fx1(x(i)+0.5*h,y(i)+0.5*h*k1); g2=Gx2(x(i)+0.5*h,y(i)+0.5*h*g1); k3=Fx1((x(i)+0.5*h),(y(i)+0.5*h*k2)); g3=Gx2((x(i)+0.5*h),(y(i)+0.5*h*g2)); k4=Fx1((x(i)+h),(y(i)+k3*h)); g4=Gx2((x(i)+h),(y(i)+g3*h)); y(i+1)=y(i)+(1/6)*(k1+2*k2+2*k3+k4)*h; z(i+1)=y(i)+(1/6)*(g1+2*g2+2*g3+g4)*h;
MATLAB: How to apply runge kutta method for system of equations that are coupled ODE’s? like x1’= -3*x2 and x2’=(1/3)*x1? I tried the code below but get an error on function define saying too may input arguments.
MATLAB
Related Question
- How to draw the graph of three species ratio-dependent predator prey model
- Equation: X”-6x’+13x = t+3sin(t) Initial Value: x(0)=1 t є [0,1] Method: Runge-Kutta II Step Sizes: h=0.1 , h=0.03
- Isqnonlin command: not enough input parameters error
- I don not get the graph when i add A1(x) in the function f1=@(x,y) A1(x)+(1.33*pi*eta*y^3)/(1+1.33*pi*eta*y^3);
Best Answer