- #1
Nick89
- 555
- 0
Hi,
I need to solve the following simple ODE with both the Euler Forward and Euler Backward numerical methods. I also need to answer for which values of T this can still be calculated:
[tex]y'(t) = \frac{-1}{2y(t)}[/tex]
[tex]y(0) = 2[/tex]
[tex]t \in (0, T][/tex]
Obviously the analytical solution is
[tex]y(t) = \sqrt{4 - t}[/tex]
So it would seem T must be between 0 and 4 for the root to be real.The Euler Forward method, if you are not familiar with it, follows from doing a taylor expansion and reads:
[tex]y_{n+1} = y_n + h y'_n[/tex]
Here, h is the 'step size'.
This method is called the explicit method because y_n+1 can be calculated explicitly by simply evaluating the right hand side, which is known.
If an initial value is known, any next value can be calculated from this. Because y(0) is given (=2) I have been able to put this into a Matlab script and graph the numerical solution, which matched the analytical solution perfectly as far as I could tell.Next, I also need to graph the solution using the Euler Backward method, which looks similar but is not quite the same:
[tex]y_n = y_{n+1} - h y'_{n+1}[/tex]
This method is also called the implicit method because y_n+1 cannot be calculated explicitly by evaluating the right hand side. Instead it needs to be solved for y_n+1.
Unfortunately, I have no clue how to build 'solve for y_n+1' into Matlab, and I'm pretty sure we are not required to do this.
So I tried just entering the ODE to get:
[tex]y_n = y_{n+1} + \frac{h}{2 y_{n+1}}[/tex]
Solving this for y_n+1 by hand, I obviously get a quadratic equation for y_n+1, for which there are two solutions:
[tex]y_{n+1} = \frac{ -y_n \pm \sqrt{y_n^2 - 2h}}{2}[/tex]Now finally my question... Of course I can use the equation above to evaluate y_n+1, but how do I know whether to use the + or the - ?
I really have no idea..? I could use the + all the time, or the - all the time, but I have no reason to believe that I should not use +, -, +, - etc or something like that. It does not sound logical to require it to use +,-,+,- etc but still, I simply don't know...
How can I determine whether to use the + or -?
Thanks!
I need to solve the following simple ODE with both the Euler Forward and Euler Backward numerical methods. I also need to answer for which values of T this can still be calculated:
[tex]y'(t) = \frac{-1}{2y(t)}[/tex]
[tex]y(0) = 2[/tex]
[tex]t \in (0, T][/tex]
Obviously the analytical solution is
[tex]y(t) = \sqrt{4 - t}[/tex]
So it would seem T must be between 0 and 4 for the root to be real.The Euler Forward method, if you are not familiar with it, follows from doing a taylor expansion and reads:
[tex]y_{n+1} = y_n + h y'_n[/tex]
Here, h is the 'step size'.
This method is called the explicit method because y_n+1 can be calculated explicitly by simply evaluating the right hand side, which is known.
If an initial value is known, any next value can be calculated from this. Because y(0) is given (=2) I have been able to put this into a Matlab script and graph the numerical solution, which matched the analytical solution perfectly as far as I could tell.Next, I also need to graph the solution using the Euler Backward method, which looks similar but is not quite the same:
[tex]y_n = y_{n+1} - h y'_{n+1}[/tex]
This method is also called the implicit method because y_n+1 cannot be calculated explicitly by evaluating the right hand side. Instead it needs to be solved for y_n+1.
Unfortunately, I have no clue how to build 'solve for y_n+1' into Matlab, and I'm pretty sure we are not required to do this.
So I tried just entering the ODE to get:
[tex]y_n = y_{n+1} + \frac{h}{2 y_{n+1}}[/tex]
Solving this for y_n+1 by hand, I obviously get a quadratic equation for y_n+1, for which there are two solutions:
[tex]y_{n+1} = \frac{ -y_n \pm \sqrt{y_n^2 - 2h}}{2}[/tex]Now finally my question... Of course I can use the equation above to evaluate y_n+1, but how do I know whether to use the + or the - ?
I really have no idea..? I could use the + all the time, or the - all the time, but I have no reason to believe that I should not use +, -, +, - etc or something like that. It does not sound logical to require it to use +,-,+,- etc but still, I simply don't know...
How can I determine whether to use the + or -?
Thanks!