QuestionQuestion

1 - Matlab Implementation code for the comparison between the 4th-order Runge–Kutta method and the exact solution.
2 - Matlab Implementation code for the comparison between the ode45 Matlab method and the exact solution.

Also write the numerical result as detailed explanation.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

%final time
tf=2;
disp(['final time = ' num2str(tf)]);

disp('table ODE45')

Abstols=5*10.^[-3:-3:-12];
nsteps=[];
MaxError=[];
for k=1:length(Abstols)
    Abstol=Abstols(k);
    [nsteps(k),MaxError45(k)]=P(tf,Abstol);
end

disp('ODE45: Tol MaxErr Nsteps ')
for k=1:length(Abstols)
    fprintf('%g %g %d \n',Abstols(k),MaxError45(k),nsteps(k));
end

%this is just to generate a plot of timestep used by ode45
to_plot=1;
P(tf,Abstol(end),to_plot);

disp('table ERK')
MaxError=[];
AbsoluteError=[];
Ns=10*2.^[3:7];
for k=1:length(Ns)
    n=Ns(k);
    [h(k),MaxError(k),AbsoluteError(k)]=erk(n,tf);
end

disp('ERK: MaxErr Nsteps h ')
for k=1:length(Ns)
    n=Ns(k);
    fprintf('%g %d %g \n',MaxError(k), n,h(k));
end


figure;
loglog(nsteps,MaxError45,Ns,MaxError,'Linewidth',2);
xlabel('N Steps');
ylabel('Max Error');
legend('ode45','erk','Location','Best');
title_str=['Comparison ODE45 and ERK, Final Time = ' num2str(tf)];
title(title_str);


%final time 8
tf=8;
disp(['final time = ' num2str(tf)]);

disp('table ODE45')...
$45.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Advanced Math Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats