Numerical methods with first order equations
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Richard Brown
2012-5-9
ode45
2 个评论
Walter Roberson
2012-5-9
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
2012-5-9
I was just answering the only part of the spiel that looked like a question (the last sentence) :)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!