y''=xy, y(0)=0, y'(0)=1, (Airy equation) step size h=0.05 and interval is [-10,2], this is system of ode, i can already solve runge kutta method but also i need airy solution i can try but not make correct graph please help me...

y''=xy, y(0)=0, y'(0)=1, (Airy equation) step size h=0.05 and interval is [-10,2], this is system of ode, I can already solve runge kutta method but also i need airy solution I can try but not make correct graph please help me...
function [x, u]= RK4_sys100(f, tspan, u0, n)
a=tspan(1);
b=tspan(2);
h=(b-a)/n;disp(h);
x=(a:h:b)';
u(1,:)=u0;
for i=1:n
k1=h*feval(f, x(i), u(i,:) )';
k2=h*feval(f, x(i)+h/2, u(i,:)+k1/2)';
k3=h*feval(f, x(i)+h/2, u(i,:)+k2/2)';
k4=h*feval(f, x(i)+h, u(i,:)+k3)';
u(i+1, :)=u(i, :)+ (k1/6 +k2/3 +k3/3 +k4/6);
end
%x=x;
%u=u;
this is my system of RK4 coad
clf;
clear u;clear x;
%forward=======================
f=inline('[u(2); x*u(1)]','x','u');
[x, u]=RK4_sys10(f, [0,2],[0,1], 40);
plot(x,u(:,1),'k') % i can take u(2)
hold on;grid on;
%backward===========================
clear u;clear x;
f=inline('[u(2); x*u(1)]','x','u');
[x, u]=RK4_sys10(f, [0,-10],[0,1], 200);
plot(x,u(:,1),'k') % i can take u(2)
%hold on;grid on;
%plot(x,u(:,2))
%disp(' x u(1) u(2)')
%disp([x u])
%axis([-10 4, -4 5]); %points of x and y axis
x=-10:0.05:2;
%plot(x,airy(2,x),'r')not this one=================
a1=airy(0,x);
a2=airy(2,x);
p=3^(2/3)*gamma(2/3); q=3^(1/3)*gamma(1/3);
r=3^(1/6)*gamma(2/3); s=3^(-1/6)*gamma(1/3);
z=[r/p*s+1/q]; y2=((r/p)*a2-a1)/z;
plot( x,y2,'-b'); %if i can not write x,ai,'-k' then plot line is one
axis([-10 4, -4 5]); %points of x and y axis
these values for solution......

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Tags

No tags entered yet.

Asked:

on 14 Sep 2014

Edited:

on 14 Sep 2014

Community Treasure Hunt

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

Start Hunting!