Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Euler Code: function [eulErr] = eulerr2(T,maxk,u0,usur,c) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This code compares the discretization errors. % The Euler and improved Euler methods are used. %

image text in transcribed

The Euler Code:

function [eulErr] = eulerr2(T,maxk,u0,usur,c) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This code compares the discretization errors. % The Euler and improved Euler methods are used. % % Inputs: % maxk = 80; % number of time steps % T = 10.0; % final time % u0 = 200.; % initial temperature % usur = 70.; % surrounding temperature % c = 2./13.; % insulation factor % % Outputs: % eulErr = k x 5 matrix of euler and improved scheme errors at time T % as well as the max errors % % Usage: [eulErr] = eulerr2b(10,5,200,70,2./13) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for k = 1:6 [ueul,err_eul,uieul,err_im_eul,uexact,time] = eulerr(T,maxk,u0,usur,c); subplot(3,2,k); plot(time,ueul,'b',time,uieul,'g',time,uexact,'r'); legend('Euler','Impr Euler','Exact','Location','NorthEast') xlabel('Time') ylabel('Temperature') title(['Exact & appro solns for maxk = ',num2str(maxk)] ); eulErr(k,1) = maxk; eulErr(k,2) = err_eul(maxk+1); eulErr(k,3) = max(err_eul); eulErr(k,4) = err_im_eul(maxk+1); eulErr(k,5) = max(err_im_eul); maxk = 2*maxk; end end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Subroutine: eulererr.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [ueul,err_eul,uieul,err_im_eul,uexact,time] = eulerr(T,maxk,u0,usur,c) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This subroutine computes the exact solution, the Euler approx solution, % the improved Euler approx solution, as well as the differences between % analytic and numerical solutions. % % Inputs: % maxk = number of time steps % T = final time % u0 = initial temperature % usur = surrounding temperature % c = insulation factor % % Outputs: % uexact = exact solution % ueul = Euler approx solution % err_eul = Improved Euler approx solution % err_eul = euler scheme error sequence % err_im_eul = Improved Euler scheme error sequence % time = time sequence (needed for plotting) % % Usage: [ueul,err_eul,uieul,err_im_eul,uexact,time] = eulerr(10,5,200,70,2./13) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% dt = T/maxk; time(1) = 0; uexact(1) = u0; ueul(1) = u0; uieul(1) = u0;

for k = 1:maxk time(k+1) = k*dt; % exact solution uexact(k+1) = usur + (u0 - usur)*exp(-c*k*dt); % Euler numerical approximation ueul(k+1) = ueul(k) +dt*c*(usur - ueul(k)); % improved Euler numerical approximation utemp = uieul(k) +dt*c*(usur - uieul(k)); uieul(k+1)= uieul(k) +dt/2*(c*(usur - uieul(k))+c*(usur - utemp)); err_eul(k+1) = abs(ueul(k+1) - uexact(k+1)); err_im_eul(k+1) = abs(uieul(k+1) - uexact(k+1)); end end

3. Consider the time dependent surrounding temperature in problem 2 above (a). Modify the MATLAB code eulerr.m to account for the changing surrounding temper- ature (b). Experiment with different number of time steps with mark = 5, 10, 20, 40 and 80 given T = 20, mazk = 5, 10, 20, 40, 80, 160, usur = 70 + t/10, uo = 200, c = 2/13, and explain what you have observed from the plot of the resulting solution curves, and table of the

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

Step: 3

blur-text-image

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago

Question

What is the purpose of a retaining wall, and how is it designed?

Answered: 1 week ago

Question

How do you determine the load-bearing capacity of a soil?

Answered: 1 week ago

Question

what is Edward Lemieux effect / Anomeric effect ?

Answered: 1 week ago

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago