Menu

Exercise 4 Write Function M File Eulerm Take 5 Input Values F T0 Y0 Dt Tf Specify Function Q43859862

Exercise 4 Now write a function M-file my euler.m which take 5 input values, f, t_0, y_0, dt, and t_f that specify the functi

Show/hide Code Snippet 1 NPOL COUW t = zeros (1,10+1); y = zeros (1,10+1); t(1) = 0; Y(1) = 1; dt = 0.2; for k = 1:10 t(k+1)

Exercise 4 Now write a function M-file my euler.m which take 5 input values, f, t_0, y_0, dt, and t_f that specify the function to be approximated, the initial t-value, the initial condition y(to) = yo, the step-size At, and the final 1-value at which you want to approximate the solution y(i). Your function should: Use the input anonymous function f to calculate f(t,y). → Plot the approximate solution with green “+” symbols at the points and a red line joining them up. → Have a function output giving the numerical value of the approximate solution to y(t) at the final 1-value, t_f. Show/hide hint Start with the code in Code Snippet 1 and think about how you need to modify it. All variables inside my_euler.m the should be calculated from the input variables so that you can run the function from the Command Window. Once you’re ready, upload your M-file using the following prompt: Choose file No file chosen Upload your M-file 0% Show/hide Code Snippet 1 NPOL COUW t = zeros (1,10+1); y = zeros (1,10+1); t(1) = 0; Y(1) = 1; dt = 0.2; for k = 1:10 t(k+1) = t(k)+dt; y(k+1) = y(k)+dt*(1-exp(-4*t(k))-2*y()); end plot(t,y,’ro-‘) t(end) y (end) Show transcribed image text Exercise 4 Now write a function M-file my euler.m which take 5 input values, f, t_0, y_0, dt, and t_f that specify the function to be approximated, the initial t-value, the initial condition y(to) = yo, the step-size At, and the final 1-value at which you want to approximate the solution y(i). Your function should: Use the input anonymous function f to calculate f(t,y). → Plot the approximate solution with green “+” symbols at the points and a red line joining them up. → Have a function output giving the numerical value of the approximate solution to y(t) at the final 1-value, t_f. Show/hide hint Start with the code in Code Snippet 1 and think about how you need to modify it. All variables inside my_euler.m the should be calculated from the input variables so that you can run the function from the Command Window. Once you’re ready, upload your M-file using the following prompt: Choose file No file chosen Upload your M-file 0%
Show/hide Code Snippet 1 NPOL COUW t = zeros (1,10+1); y = zeros (1,10+1); t(1) = 0; Y(1) = 1; dt = 0.2; for k = 1:10 t(k+1) = t(k)+dt; y(k+1) = y(k)+dt*(1-exp(-4*t(k))-2*y()); end plot(t,y,’ro-‘) t(end) y (end)

Expert Answer


Answer to Exercise 4 Now write a function M-file my euler.m which take 5 input values, f, t_0, y_0, dt, and t_f that specify the f…

OR