Hello,
Here is the task that i have to solve:
y1' = y2
y2'=f(x,y1,y2) with y1(0)=0 and y2(0)=y20
where f(x,y1,y2) = -axy2-y1, a=0.03 and y20 = 0.25
and here is my matlab code:
—
function mainh = pi/10;x = 0 : h : 2*pi;n = length(x);y(1,1)=0; y(2,1) = 0,25;for k = 1: (n-1) k1 = h * rung(x(k), y(1:2,k)); k2 = h * rung(x(k) + h/2, y(1:2,k) + k1/2); k3 = h * rung(x(k) + h/2, y(1:2,k) + k2/2); k4 = h * rung(x(k) + h, y(1:2,k) + k3); y(1:2,k+1)=y(1:2,k) + (k1 + 2*k2 + 2*k3 + k4)/6;endfigure(1), plot(x, y(2,:)) %everything from second row
figure(2), plot(x, y(1,:), x, ??, '*')function f=rung(x,y)f(1,1) = y(2); f(2,1) = -0,03*x*y(2) – y(1);
So, my question is – Is this correct or not? And what would be the best option for h and x.
And how can i found and use numerical solution? Because i know that instead of the question marks here figure(2), plot(x, y(1,:), x, ??, '*') should be the exact numerical solution.
Best Answer