Question

Using MATLAB Solve 2x5 5х, x(0)0, a(0) 0.4, on the interval [-2,0] Use Taylor series method or Runge-Kutta method

0 0
Add a comment Improve this question Transcribed image text
Answer #1


2n- 5 CO) Let du Thp dnz 22 dt - 5U U 2 dt 2 thin at ping ere se uNiMatlab code for RK4 solution f1- (t,x1,x2) x2; f2- (t,xl,x2) 2*x2-5*xl; %all step size h-0.01 al conditions x10-0 x20 0.4 %x2x(t) vs. t plot 0.04 0,02 0 -002 0.04 -0.06 -0.08 -0.12 -0.2 -0.6 -08 1 2 1.6 1.4 18 t dx(t)/dt vs. t plot 03 02 0.1 -0.2 0 4


%Matlab code for RK4 solution

f1=@(t,x1,x2) x2;
f2=@(t,x1,x2) 2*x2-5*x1;
%all step size
h=-0.01;
%Initial conditions
x10=0;     %x1(0)=0
x20=0.4;   %x2(0)=0.4
%initial t
t0=0;
%t end values
tend=-2;
tn=t0:h:tend;
x1_rk(1)=x10; x2_rk(1)=x20; t_rk(1)=t0;
%Runge Kutta 4 iterations
for i=1:length(tn)-1
  
    k0=h*f1(t_rk(i),x1_rk(i),x2_rk(i));
    l0=h*f2(t_rk(i),x1_rk(i),x2_rk(i));
    k1=h*f1(t_rk(i)+(1/2)*h,x1_rk(i)+(1/2)*k0,x2_rk(i)+(1/2)*l0);
    l1=h*f2(t_rk(i)+(1/2)*h,x1_rk(i)+(1/2)*k0,x2_rk(i)+(1/2)*l0);
    k2=h*f1(t_rk(i)+(1/2)*h,x1_rk(i)+(1/2)*k1,x2_rk(i)+(1/2)*l1);
    l2=h*f2(t_rk(i)+(1/2)*h,x1_rk(i)+(1/2)*k1,x2_rk(i)+(1/2)*l1);
    k3=h*f1(t_rk(i)+h,x1_rk(i)+k2,x2_rk(i)+l2);
    l3=h*f2(t_rk(i)+h,x1_rk(i)+k2,x2_rk(i)+l2);
    t_rk(i+1)=t0+i*h;
    x1_rk(i+1)=double(x1_rk(i)+(1/6)*(k0+2*k1+2*k2+k3));
    x2_rk(i+1)=double(x2_rk(i)+(1/6)*(l0+2*l1+2*l2+l3));
  
end
%plotting the result
figure(1)
plot(t_rk,x1_rk,'Linewidth',2)
xlabel('t')
ylabel('x(t)')
title('x(t) vs. t plot')
grid on
box on

%plotting the result
figure(2)
plot(t_rk,x2_rk,'Linewidth',2)
xlabel('t')
ylabel('dx(t)/dt')
title('dx(t)/dt vs. t plot')
grid on
box on

%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Using MATLAB Solve 2x5 5х, x(0)0, a(0) 0.4, on the interval [-2,0] Use Taylor series method...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT