Solve x′′ = −x − α(x2 − 1)x′, 0 ≤ t ≤ 30, with the initial conditions x(t = 0) = 0.5 and x′(t = 0) = 0, using RK4 method in your computer where α = 1. Plot the solution.

1 view (last 30 days)
Urgent. Please solve it with explanation as soon as possible.
  3 Comments
KAUSHIK JAS
KAUSHIK JAS on 12 Sep 2019
Edited: KAUSHIK JAS on 12 Sep 2019
I am a beginner of matlab.Not able to write this code. If you can do then answer it.
James Tursa
James Tursa on 12 Sep 2019
Edited: James Tursa on 12 Sep 2019
There are many people on this forum that can write the code for this, but we don't do that for homework problems. You must show some effort first, and then we can help you solve your coding problems. To code an RK4 scheme from scratch, I would first suggest you look at the equations here and try to code them up:
The RK4 equations are spelled out. Just remember that your "y" and "k"s will be 2-element vectors since you have a 2nd order ODE to solve.

Sign in to comment.

Answers (1)

KAUSHIK JAS
KAUSHIK JAS on 22 Sep 2019
I solve it correctly by my own. It is in below.
%RK2 of two variables
h=0.5;
t=0:h:30;
x=zeros(1,length(t));
z=zeros(1,length(t));
alpha=1.0;
x(1)=0.5;
z(1)=0;
f=@(p,q,r) (r);
g=@(p,q,r) (-q-alpha*(q^2-1)*r);
for i=1:(length(t)-1)
k11=h*f(t(i),x(i),z(i));
k12=h*g(t(i),x(i),z(i));
k21=h*f(t(i)+0.5*h,x(i)+0.5*k11,z(i)+0.5*k12);
k22=h*g(t(i)+0.5*h,x(i)+0.5*k11,z(i)+0.5*k12);
k31=h*f(t(i)+0.5*h,x(i)+0.5*k21,z(i)+0.5*k22);
k32=h*g(t(i)+0.5*h,x(i)+0.5*k21,z(i)+0.5*k22);
k41=h*f(t(i)+h,x(i)+k31,z(i)+k32);
k42=h*g(t(i)+h,x(i)+k31,z(i)+k32);
x(i+1)=x(i)+(1/6)*(k11+2*k21+2*k31+k41);
z(i+1)=z(i)+(1/6)*(k12+2*k22+2*k32+k42);
end
subplot(2,1,1);
plot(t,x);
subplot(2,1,2);
plot(t,z);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!