1. Consider the first example that we introduced in part 1. If the problem is changed to be as follows :
Solve the equation for t from 0 to 5 : dy/dx = -2x + y Initial condition : xt=2.5 = 1We can see that the time of the initial condition is t = 2.5 but not t = 0 but the range of the solution we need to find is still setted from 0 to 5. So, how can we solve this problem ?
In this case, we need to separate the problem into two parts. The first part is from t=2.5 to t=5. The second part is from t=2.5 to t=0. Here is how we do it :
Ans. set r = 2.5, 3, 3.5, 4, 4.5, 5, 1, -1.891, -7.304, -16.876, -33.304, -61.032
For the second part :
Ans. set r = 2.5, 2, 1.5, 1, 0.5, 0, 1, 2.359, 2.791, 2.66, 2.187, 1.507
See the the interval value is now a negative value -0.5.
We can then reverse f(0) using the function 'rev'and join it with d(0) to get the solution of the whole range.
Ans. set h = 1.507, 2.187, 2.66, 2.791, 2.359, 1, 1, -1.891, -7.304, -16.876, -33.304, -61.032
To get a plot of the solution, we also needed to reverse and combine the t values :
Ans. set k = 0, 0.5, 1, 1.5, 2, 2.5, 2.5, 3, 3.5, 4, 4.5, 5
The plot is shown below :
The exact solution of this problem is the formula below :
y = 2 - 6e(x-2.5) + 2x
We can check our numerical solution h by using k as x and calculate y :
Ans. 1.507, 2.188, 2.661, 2.793, 2.361, 1, 1, -1.892, -7.31, -16.89, -33.334, -61.095
2. The second variation from the general ode problem is also about the change in initial condition. Consider the following example
Solve the equation for x from 0 to 10 : d2y/dx2 = √(1 + (dy/dx)2) y(0) = 2, y(10) = 0For this problem, only the values of the boundary are given but the initial value of dy/dx is unknown. These kind of problem is called 'boundary value problem'. So, how can we solve this problem ?
In this case, we can try to use a method called 'shooting'. The idea is quite simple. We try different initial values of dy/dx and see if the resulted value of y(10) is 0. If it is, then we had done.
First, we rename variables and reduce the problem into two first order odes :
Solve the equation for t0 from 0 to 10 : dx0/dt0 = x1 dx1/dt0 = √(1 + (x1)2) x0t0=0 = 2, x0t0=10 = 0We set x as the initial value of dx0/dt0t0=0 and try to find x0(10). Below are the inputs that can do the search :
Here, we use the function 'euode' instead of 'rkode' since 'euode' is a much faster method.
With the above inputs, we can now do the shooting. For example, we set x=0 to see what is y(10) :
Ans. 4848.1
y(10) is found to be 4848.1.
Now, we try x = 50,
Ans. 455023.5
For x = -50,
Ans. 57.33
For x = -80,
Ans. -6.35
So, it seems that zero should exists between -50 to -80. We can continue to try to input different x to find the output. Or, we can actually do a zero search between -50 to -80 as follows with error level set to 0.1 (default is 0.001) :
Ans. -76.4375
It takes some time for this search step and finally we get the answer -76.4375. When we put the value x= -76.4375, y(10) would be -0.061.
Ans. -0.061
It can be seen that when the initial dy/dx is set to -76.4375 at x=0, then we get y(10) = -0.061 which is quite close to 0 and so we treat the calculated r and d from c as our solution.
To get a plot of the solution :
The resulting graph is :
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.