RangaKutta Method Vs Analytic Method plot problem
Show older comments
x_a=linspace(0,2,n)
h=x_a(n)-x_a(n-1)
y_a=((x_a.^2+1/2.*x_a+1)).^2
y_r(1)=1;
for i=1:n-1 ;
x_r=linspace(0,2,n)
h_r=x_r(n)-x_r(n-1);
k2_x(i)=x_r(i)+h_r/2;
k1(i)=(1+4.*x_r(i)).*sqrt(y_r(i));
k2_y(i)=y_r(i)+k1(i)./2;
k2(i)=(1+4.*(k2_x(i)).*sqrt(k2_y(i)));
k3_y(i)=y_r(i)+k2(i)./2;
k3(i)=(1+4.*k2_x(i)).*sqrt(k3_y(i));
k4_x(i)=x_r(i)+h_r;
k4_y(i)=y_r(i)+k3(i);
k4(i)=(1+4.*k4_x(i)).*sqrt(k4_y(i));
y_r(i+1)=y_r(i)+h_r.*(k1./6+k4./6+k2./3+k3./3)
i=i+1;
plot(x_a,y_a,'--kd')
hold on
plot(x_r,y_r,'--y+')
end
This is program to plot graph between RangaKutta Method Vs Analytic Method.
But the dont know why the graph is not plotting.Its giving the value of y_r ,two times only.Although it should give the values n times.
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!