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 (최근 30일)
KAUSHIK JAS
KAUSHIK JAS 2019년 9월 12일
답변: KAUSHIK JAS 2019년 9월 22일
Urgent. Please solve it with explanation as soon as possible.
  댓글 수: 3
KAUSHIK JAS
KAUSHIK JAS 2019년 9월 12일
편집: KAUSHIK JAS 2019년 9월 12일
I am a beginner of matlab.Not able to write this code. If you can do then answer it.
James Tursa
James Tursa 2019년 9월 12일
편집: James Tursa 2019년 9월 12일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

KAUSHIK JAS
KAUSHIK JAS 2019년 9월 22일
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!

Translated by