5 xy eulerh 0 0 4 f plotxy g xy h 025 xy eulerh 0 0 4

This preview shows page 6 - 9 out of 13 pages.

00.511.522.533.544.500.511.522.5
3.4 a.As can be easily verified, the solution to the initial value problem in Example 3.3 is h(x) = -cos(x) + 2Now with the solution of the above differential equation, we can compare the results obtained by using ode45 to the actual values. Type the following commands into MATLAB: >> h = @(x) -cos(x) + 2; [x, y, h(x), abs(y - h(x))] Include this code and the output in your writeup. The second and third columns give us the estimate that we found using ode45 and the actual function value at each specified value of x. How do the values in the two columns compare? The fourth column gives the
b.Now let us compare the results that ode45 gives us with the results we would get from using Euler's method. Enter the following commands into MATLAB: >> [x, z] = Euler(0.25, 0, 1, 10, g); [y, z, h(x), abs(y - h(x)), abs(z - h(x))] Copy the input and output to your Word document. In the first column, we have the results of ode45; in the second, the results of our Euler's Method routine; and in the third, the values at xof the real solution to our differential equation. Columns four and five give the error of ode45

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture