Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do you plot these four codes on one set of axes? You might not need the codes to tell me how but I listed

How do you plot these four codes on one set of axes? You might not need the codes to tell me how but I listed them anyway.

*****Codes:

Euler's Method:

function Euler() % We will use Euler's method to investigate the first order DE dy/dt=cos(t-y) with initial condition y(0)=1 clear t % Clears all t inputs clear y % Clears all y inputs ti=0; % This is the left endpoint of our interval, t initial h=1; % This is the step size, distance between t values tf=100; % This is the right endpoint of our interval, t final n=(tf-ti)/h; % This is the total amount of steps t(1)=ti; % Declares the starting t value for the loop y(1)=1; % This is the value of the initial condition at the first iteration of the loop for j=1:n t(j+1)=h+t(j); y(j+1)=y(j)+h*cos(t(j)-y(j)); end figure(1) plot(t,y) xlabel('t') ylabel('y(t)') title('Euler') hold on % Allows plotting multiple solutions on the same set of axes grid on % Outputs xy-axes for plot

Improved Euler:

function ImprovedEuler() % We will use improved Euler's method, the one that corresponds to the midpoint method, % to investigate the first order DE, dy/dt=cos(t-y) with initial condition y(0)=1 clear t % Clears all t inputs clear y % Clears all y inputs ti=0; % This is the left endpoint of our interval, t initial h=1; % This is the step size, distance between t values tf=100; % This is the right endpoint of our interval, t final n=(tf-ti)/h; % This is the total amount of steps t(1)=ti; % Declares the starting t value for the loop y(1)=1; % This is the value of the initial condition at the first iteration of the loop for j=1:n t(j+1)=h+t(j); f(j)=cos(t(j)-y(j)); y(j+1)=y(j) + h*f(j)/2 + h*cos(t(j)+h-y(j)-(h*f(j)))/2; end figure(2) plot(t,y) xlabel('t') ylabel('y(t)') title('Improved Euler') hold on grid on

Runge Kutta:

function RungeKutta() % We will use Runge-Kutta, the method that corresponds to the trapezoidal weighted average, % to investigate the first order DE dy/dt=cos(t-y) with initial condition y(0)=1 clear t % Clears all t inputs clear y % Clears all y inputs ti=0; % This is the left endpoint of our interval, t initial h=1; % This is the step size, distance between t values tf=100; % This is the right endpoint of our interval, t final n=(tf-ti)/h; % This is the total amount of steps t(1)=ti; % Declares the starting t value for the loop y(1)=1; % This is the value of the initial condition at the first iteration of the loop for j=1:n t(j+1)=h+t(j); f(j)=cos(t(j)-y(j)); k1(j)=f(j); k2(j)=cos(t(j)+h/2-y(j)-(h*k1(j)/2)); k3(j)=cos(t(j)+h/2-y(j)-(h*k2(j)/2)); k4(j)=cos(t(j)+h-y(j)-(h*k3(j))); y(j+1)=y(j)+(h*k1(j)/6)+(h*k2(j)/3)+(h*k3(j)/3)+(h*k4(j)/6); end figure(3) plot(t,y) xlabel('t') ylabel('y(t)') title('Runge-Kutta') hold on grid on

Plot Code:

% For loop to plot temperature vs time for A=115:4:125 T=0:100 B=(98.6-A)*exp(-0.054*T)+A; plot(T,B); hold on end

title('Body Temperature vs Time'); xlabel('Time (min)'); ylabel('Body Temperature (Fahenheit)'); grid on;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions

Question

WHAT IS AUTOMATION TESTING?

Answered: 1 week ago

Question

What is Selenium? What are the advantages of Selenium?

Answered: 1 week ago

Question

Explain the various collection policies in receivables management.

Answered: 1 week ago