In: Advanced Math
Use numerical integration to calculate the solution of Airy’s differential equation x''=tx from initial conditions x(-14.5)=0 and x'(-14.5)=1 until t =3.
Then plot the curve. Be sure to sample the curve frequently enough that it appears smooth.
%%Matlab code for system of ODE using Euler's forward
clear all
close all
%Euler forward for question
%functions for Euler equation solution
f1=@(x1,x2,t) x2;
f2=@(x1,x2,t) t.*x1;
% step size
h=0.0001;
%Initial values
x10=0;
x20=1;
t0=-14.5;
%x end values
tend=3;
tn=t0:h:tend;
% Euler steps
x1_result(1)=x10;
x2_result(1)=x20;
t_result(1)=t0;
%solution for Euler forward scheme
for i=1:length(tn)-1
t_result(i+1)= t_result(i)+h;
x1_result(i+1)=x1_result(i)+h*double(f1(x1_result(i),x2_result(i),t_result(i)));
x2_result(i+1)=x2_result(i)+h*double(f2(x1_result(i),x2_result(i),t_result(i)));
end
figure(1)
plot(t_result,x1_result)
title('Solution plot for step size dt=0.0001')
xlabel('t')
ylabel('x(t)')
%-------------------------------------------------------------%