Numerical methods with first order equations

2 views (last 30 days)
Ali
Ali on 9 May 2012
As can be easily verified, the solution to the above initial value problem is
g(x) = - cos(x) + 2
Now 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
>> g = inline('-cos(x)+2')
>> [x,y,g(x),abs(y-g(x))]
Include the output in your writeup. The second and third columns give us the estimate that we get by using ode45 versus the actual function value at specified each value of x. How do the values in the two columns compare? The fourth column gives the absolute value of the difference between the function and our approximation.
(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:
>> f = inline('sin(x)', 'x', 'y');
>> [x, z] = Euler(0.25, 0, 1, 10, f);
>> [y, z, g(x), abs(y - g(x)), abs(z - g(x))]
In the first column we have the results of ode45, in the second from our Euler's method routine, and in the third the values at x of the real solution to our differential equation. Columns four and five give the error of ode45 and Euler's method, respectively. Which method seems to give more accurate answers in this situation?

Answers (1)

Richard Brown
Richard Brown on 9 May 2012
ode45
  2 Comments
Walter Roberson
Walter Roberson on 9 May 2012
We don't know that. The problem requires the inheriting of x and y, but we do not have proof that the y is produced by MATLAB's ode45 routine.
Richard Brown
Richard Brown on 9 May 2012
I was just answering the only part of the spiel that looked like a question (the last sentence) :)

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!