(Solved) : Function Altered Function T V Euler M C G T0 V0 Tn N Print Headings Initial Conditions Fpr Q43912449 . . .
The function to be altered isbelow:
function [t,v] = Euler(m,c,g,t0,v0,tn,n)
% print headings and initial conditions
fprintf(‘values of t approximations v(t)n’)
fprintf(‘%8.3f’,t0),fprintf(‘%19.4fn’,v0)
% compute step size h
h=(tn-t0)/n;
% set t,v to the initial values
t(1)=t0;
v(1)=v0;
% compute v(t) over n time steps using Euler’s method
for i=1:n
v(i+1)=v(i)+(g-c/m*v(i))*h;
t(i+1)=t(i)+h;
fprintf(‘%8.3f’,t(i+1)),fprintf(‘%19.4fn’,v(i+1))
end
end
Question #2 – 6 Marks. Newton’s law of cooling says that the temperature of a body changes at a rate proportional to the difference between its temperature and that of the surrrounding medium (the ambient temperature) dT di = -k(T – T.) where T is the temperature of the body (°C), t is time (minutes), k is the proportionality constant (per minute), and T, is the ambient temperature (°C). (a) Modify the MATLAB function Euler in Question 1 so that it will use Euler’s method to solve this differential equation. Use the function header function Euler2(k , Ta, to , TO, tn , n) where Ta = Ta, the initial condition TO = T(to), tn is the final value of t in the numerical solution, and n is the number of time steps. DELIVERABLES: A copy of the M-FILE in your pdf. (b) Use Euler2 to compute a numerical approximation to the above differential equation using k = 0.019/min, T, = 20°C and initial condition T(0) = 68°C on the time interval 10, 12 using a step size of 0.125 minutes. DELIVERABLES: The function call to Euler2 and the resulting output. (c) Use the fact the exact analytic solution of this problem is T(t) = 20 + 48e-0.019 to compute (either in MATLAB or using your calculator) the relative error in the computed solution at t= 12. Show transcribed image text Question #2 – 6 Marks. Newton’s law of cooling says that the temperature of a body changes at a rate proportional to the difference between its temperature and that of the surrrounding medium (the ambient temperature) dT di = -k(T – T.) where T is the temperature of the body (°C), t is time (minutes), k is the proportionality constant (per minute), and T, is the ambient temperature (°C). (a) Modify the MATLAB function Euler in Question 1 so that it will use Euler’s method to solve this differential equation. Use the function header function Euler2(k , Ta, to , TO, tn , n) where Ta = Ta, the initial condition TO = T(to), tn is the final value of t in the numerical solution, and n is the number of time steps. DELIVERABLES: A copy of the M-FILE in your pdf. (b) Use Euler2 to compute a numerical approximation to the above differential equation using k = 0.019/min, T, = 20°C and initial condition T(0) = 68°C on the time interval 10, 12 using a step size of 0.125 minutes. DELIVERABLES: The function call to Euler2 and the resulting output. (c) Use the fact the exact analytic solution of this problem is T(t) = 20 + 48e-0.019 to compute (either in MATLAB or using your calculator) the relative error in the computed solution at t= 12.
Expert Answer
Answer to The function to be altered is below: function [t,v] = Euler(m,c,g,t0,v0,tn,n) % print headings and initial conditions fp…
OR