In this video I'll go over how to apply the shooting method to nonlinear differential
equation.
After studying this video you should be able to formulate the shooting method as a roots
problem when applying the strategy to a nonlinear ordinary differential equation and implement
the shooting method for a nonlinear boundary valued problem.
Recall that the shooting method algorithm is a combination of tools that we already
have.
The first step is to convert the boundary value problem into an equivalent initial value
problem.
Then we're gonna guess any undefined values for the initial conditions.
Often that's gonna be guessing DYDX at x equals zero.
We'll take that guess using initial value problem solver to integrate the differential
equation and modify our guess until we want our end of the integration
to hit the target.
That's always gonna be our second boundary condition.
In this case YL.
So we'll change those guesses until we find the initial guess that hits the target.
In a previous video we saw that for a linear differential equation we only need two shots
and then we can use linear interpolation to find the initial guess that hits the target.
For a nonlinear differential equation we're gonna have to set this up as a roots problem
because linear interpolation does not get us to the correct guess.
So let's look at how we do that.
So the basic idea here is to treat the end point of the ODE integration as a function.
Here's our ODE function, DYDX, and we'll call ODE 45 or some other initial value problem
solver to integrate that function with an initial guess for our second boundary condition.
And we'll just call that Z.
And then we'll define this function f of z as, where did we end up, so this is our endpoint
of the integration.
So the idea of this function is coming back to our shooting method algorithm, is Z. Z
is our guess at the slope if the slope is our unknown initial condition.
It's the guess at the slope DYDX at X equals zero.
If we do that guess then we put that into our function and the result of the function
would be our end value.
So that would be our F of Z.
So, now we've defined that function F of Z being the end value of our integration given
an initial guess Z.
We know that the accurate shot is gonna occur while F of Z is equal to YL and we can use
that to formulate a roots problem.
So the residual in the roots problem, recall the concept of a residual, so the residual
of the roots problem is gonna just be F of Z minus YL and we want to find the value of
Z, find the value of Z, again that's our initial condition guess, such that F of Z equals YL,
or F of Z minus YL is equal to zero, or the residual of the roots problem F of Z minus
YL is equal to zero.
So again, our basic roots problem is saying F of Z is equal to YL.
Then we'll use the root finding method to solve the roots problem.
So we can use fzero, MATLAB's built in function for roots problems.
Finally, we use that result, that of Z, for the initial condition guess to finally integrate
our ODE to the target boundary condition.
So let's look at how this works with an example.
So here's a nonlinear boundary value problem to solve for the temperature distribution
in a heated rod.
So the temperature distribution is described by the following differential equation.
We have the second derivative of temperature with respect to X plus H prime times T infinity
minus T plus sigma prime times T infinity to fourth, minus T to the fourth, is equal
to zero.
Let me define some of these parameters.
So T infinity is just the ambient temperature.
So in this case we're saying we have a rod out in an ambient temperature of 200 Kelvin
and the rod is heated because on the lefthand side, we'll call this T zero, that's equal
to 300 Kelvin.
That's one boundary condition.
And on the righthand side of the rod, we'll call this TL, that's equal to 400 Kelvin,
or X equals 10.
The two coefficients, H prime and sigma prime, are bulk heat transfer coefficients combining
the effects of conduction and convection in H prime, and conduction and radiation in sigma
prime.
So, what we're gonna do is use this differential equation to solve for the temperature distribution
T of X.
So here is the MATLAB code to solve this problem using the shooting method.
And we actually need three m-files to make this work.
So our first m-file here, what we're doing is using fzero to find the initial condition
guess that hits the target.
So we'll use fzero to call a function bar_res, which is the residual, the function that defines
the residual for fzero.
And this is just our initial guess.
So let's first look at bar_res.
So bar_res is down as actually our third function on this slide, down here, here's bar_res.
And what bar_res does is takes our initial condition guess.
Remember we're using fzero to solve that roots problem for the initial condition guess.
We take that initial condition guess.
We're gonna use it here as our second initial condition to call ODE 45 and we call ODE 45.
Take the last value and subtract TL and this gives our residual for the roots problem.
Then again fzero is now using that function bar_res to find the value of X such that we
want that R to go to zero.
Bar_temp, the other function involved here, that's our DYDX, and we see bar_temp again
here.
And now, in this we've often been using anonymous functions to define our ODE functions but
in this case it really makes sense to use an external file.
So I've done that in our third m-file right here.
And the reason it makes sense to use an external file is because we're calling it once from
our main file, the same file that we're calling fzero from, and then we're calling it a second
time from the function file that defines bar_res.
So in bar_temp we see our constants are defined here.
And just as we've been doing we define DTDX as a system of two first order differential
equations for the initial value problem solver that we're using.
ODE 45 in this case.
So let's go through this one more time.
So what MATLAB does is, the first thing we're doing, is we're using fzero to use this residual
function where we take the final value from the integration, subtract the second boundary
condition, and we want that to be zero.
So that's our roots problem.
Fzero is gonna find the value of ICguess, which is what the value of x is in our general
F of X formulation for fzero.
That translates to ICguess.
Fzero is gonna find the value of ICguess.
Then we're gonna use that value of ICguess that we have here as our second initial condition
to send to ODE 45 for our final integration.
So we might have, depending on how many iterations it takes for fzero, we have, say it takes
ten iterations for fzero, to solve this one problem we're gonna call ODE 45 eleven times.
One time for each of the ten iterations in fzero plus a final time with our successful
on target initial condition.
So let's look at the result.
So I've shown the figure again here so you can kind of visualize what's happening with
the temperature.
We have heat transfer due to radiation, conduction, and convection considered.
And as we expect our boundary conditions, we have 300 at the lefthand side, and 400
at the righthand side, at X equals 10.
And the temperature decreases as we go along the length of the bar and increases back up
to 400 hitting a minimum value of about 240.
So I'd encourage you to download these m-files, step through them to really understand what
is going on as fzero is calling our bar_res function and then going to ODE 45 to get the
value it needs for the end of the integration to formulate the roots problem and finally
iterating in fzero to find our target, on target initial condition guess and use that
as the second initial condition for the final integration with ODE 45.
And that concludes this video.
Không có nhận xét nào:
Đăng nhận xét