Question: 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

 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

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)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!