Numerical Methods in Maple
Transcript
Uh so I'll get started. Uh I'm going to give a workshop on numerical dees in Maple uh today and uh I've got a lot of material that we can cover or if I have questions we can always um expand on something uh add information, try other things. Um, you've all been sent a link uh in the chat to this very worksheet that I'm going to be using to to show. Uh, so for one, you can follow along in the worksheet if you like. Um, you can use the worksheet as a starting point to try other things, uh, change things around, modify something to be one of your problems. If you run into any um issues or don't understand something, by all means, uh type something into the chat and um and somebody will either answer the the question or direct it to me and uh I can answer it for everyone. Okay. So, we might as well looks like people are still joining. Oh, yeah. By the way,
I'm Allan Wittkopf, fellow at Maplesoft. Uh so I'm gonna get started now. Um so I'm just going to start with an overview of the type of stuff you can do uh with numerical dees uh in Maple. So we have tools for visualizing numerical sol and computing numerical solutions of systems of differential equations for regular initial value problems, boundary value problems, delay differential equations, differential algebraic equations and partial differential equations. So for any of the univariate stuff, initial value problems, boundary value problems and the like, uh dsolve is the command you want to use and the numeric option gives you the
uh numeric solution as opposed to an attempted an exact. So very simple example um harmonic oscillator uh initial conditions y at 0 is one and y prime at 0 is zero. We just call dolve with this system and the numeric option and it gives us a solution and we can use this to compute a value at any point we like. Um just request the value. Boundary value problems. Well, that's just a like an initial value problem, but now you're specifying um conditions at more than
one independent variable point. In this case, um, I'm specifying a value at zero and at one for this differential equation here. Again, just throw it into d solve. You get a solution procedure and you can ask for a value at a point. This uh you pro this is a recap of a lot of the stuff from yesterday, but OD plots can give you a plot of your solution. Um so we try to make everything
as easy to use as possible. So if you just call it with the solution, it detects well yeah this was a boundary value problem over 0 to one. So chooses the right range for the independent variable. um leading nonlinear OD uh in this case the highest derivative in the equation is um not linear simply a quadratic and for those type of initial value problems this can be treated as a DAE and uh we can obtain a solution for these as well uh pretty straightforwardly And
um you'll notice we've provided a an extra initial condition and we need that because of the arbitrariness of the square. Y prime can be positive or negative and give the same value out of y prime squared. Okay. Um we also support more complicated DAE of course uh higher index and a simple delay equation with a delay of one. Okay, we can just again pass it in a delf. We can get a plot and the plot's a bit interesting
because you can see that for the first second it looks pretty constant. a nice constant slope which is a reflection of the fact that the initial condition y at zero is zero is being assumed for all prior times as well and then it starts changing more smoothly. Okay, so PDEs are are a little limited at this point to one space one-time PTEES and the PTE solvers that we have well the PTE methods that get used was always intended uh on the initial design to be using it in a
course because we've got a lot of the standard techniques that get taught in courses available uh and there's a help page uh to describe all the basic techniques uh like Lax Friedri's leapfrog my apologies and de for Frankle um for a standard PTE you don't need to specify the methods you just uh pass in your PTE problem in this case we've got the PTE and the conditions specified separate
initial and boundary conditions and instead of a procedure we now get a solution module uh just because it was more convenient ient to do this way because then you could get direct access to 3D plotting plotting directly through the module itself. So the module form we can ask for the value for t equals 1 and it gives us a procedure that looks a lot like the one we got from dolves. So a single variable procedure that we can use to evaluate and we could have used the procedure
itself or we could just simply ask for a plot directly from the returned module. The returned module also produces animations directly. So we can ask for an animation from t is 0 to 1 and it just gives us an animation automatically and we can also get a plot a 3D plot of the solution as a function of time and space. So that's just an outline of the facilities that are available in Maple at this time. Um so I'm going to get into a bit more detail on some of these. Uh so for IVP
specifically uh there are a lot of options and I'm going to describe also the interactive features of initial value problems and not the interactive feature I showed yesterday which was the dolve interactive but rather the ones that you can use from command line. So we have high accuracy techniques like Taylor series um and I'm going to briefly demonstrate how fast that is. Uh we have step solvers uh like Rosen Brock and LSOD. We have handling events. These are discrete actions
that happen in the course of integration. You can reinitialize. You can run a state machine. Uh and like I said discrete variable state machines is kind of tied into event handling. Um, a lot of these have links. Uh, if you've got the worksheet and you click on one of these links, it'll just take you right to the help page that describes these in explicit detail. Um, the event handling page also describes discrete variables and state machines. Uh, parameters, we can support parameterized problems and do the computation on request. uh we have the compile option and it's quite a strong thing to be able to do if you can comp combine the compile option with parameters. So you can parameterize uh a problem and have a compiled code running under the hood that very rapidly gives you different solutions for different values of the parameters. You set the parameters,
obtain a solution and so on. This is good for parameter optimiz optimization which you'll see later and as I mentioned the interactive design we're going to show a bit about that. So high precision um this Maple of course works with arbitrary digits. Uh you just specify a digit setting and that's the precision it will work in. For this problem, I'm going to set digits to 30. And I'm going to try and solve basically just the harmonic oscillator. Uh, and in fact, it's a sign solution. And I'm going to specify that I want an absolute error and relative error of no more than 1 eus 25. And I'm going to try and use a high order RK pair diver 78.
So we're going to see how long it takes to compute this out to 10 with roughly about 25 digits of precision. And it's not fast um even for a order 7 8 pair. So tail and we can compare and make sure at least we're getting the right solution and in fact it does match up and we can ask okay how many function evaluations did we need to do and it was quite a few 42,000 um if we can do the same with Taylor series which is designed for higher accuracy and it's quite a
bit quicker and gives quite similar precision in in this case a little bit better but you've only specified a tolerance of 20 minus 25. So so you can see the time difference is quite substantial. Uh and Taylor series is what you want to use if you have um high accuracy solution requirements. Um briefly stiff problems. Uh this is a standard stiff problem. We're going to attempt to attack
it with uh just the standard RKF45 technique. And we can see that in order to compute the solution out to t= 10 took us 20,000 um roughly about 20,000 function evaluations. The same thing with the stiff method. Uh and you can just simply specify stiff equals true in the call to dull. and that computation only did 588 right- hand side evaluations. So, it's using a stiff method for a stiff problem is much more efficient always. Uh again, links to help pages on these. Okay,
events. Uh events take a bit of description. Okay. Uh there are two parts to an event. There's the trigger which is basically asking the question when should the event occur and then there's the action what should we do when the event does occur. Um so standard triggers uh expression passes through zero. So uh and you can express passes through zero when a condition is true. And this is great if you want to only fire an event
um under some circumstances. uh expression goes outside a specified range. So if you have a problem where you know that a value needs to be within a certain range and you want to stop and uh reassess what you're doing if it goes outside that range. Uh you can just specify the range and it'll stop when it goes outside. You can do a specific time value or a periodic value. Um, for example, you can have something start at t equals 2 and trigger every half second after that. Okay,
that's how you set up triggers. Um, action. Uh, the most obvious one is halt. Uh, once you achieve this event, you may want to stop a simulation. You may want to execute a statement or multiple statements. You may want to run a state machine. Uh again a state machine would be uh via statement or multiple statements but uh in addition you for a state machine you'd want discrete variables and uh I'll show briefly how to do that uh here. So, I'm going to define an event or a model.
And I just have a simple model here. Y prime= y. And I'm going to say if we hit y = 2, stop. And when we try to integrate out to 10, it tells us uh can't evaluate the solution further right of this value and event one trigger a halt. and then gives us the solution value at that time. So we can see that yeah this did exactly what we asked it to do. At this time y hit two and we stopped. Um we can do something different. We can say well instead of halting let's reset the value
of y back to one uh every time it hits two. And we get this. So goes up to two reset up to two reset. So this is like a for those familiar with the terminology, this is a reinit. So we reinitialize the problem every time it hits a certain value. And I'm just going to modify this one slightly to show what you need to do to use a discrete variable. So we have exactly the same problem, but I'm adding uh something called numbum reset. And what I want to do is I want to count the
number of times we had to do a reset. I declare that as a discrete variable here and then I define the event with a action with two statements reset Y back to one and increment num reset by one. So we run that and we can plot num reset and say well how many times have we reset and we can see that the stair it creates a staircase that you know pretty much mirrors the behavior we saw in the plot.
Um so if you run um the simulation there are a couple of interactive triggers or interactive features like you say how many events fired and when was the last time event one fired. So this is part of the interactivity. We'll see more on that later. Uh and that's it for events um for what I'm going to discuss here but there is a lot of detail uh and other examples in the help pages uh parameters and compiling. Okay. Uh initial value problem solutions are done on request.
So what you're returned is a computation engine that you can use to ask for values and the values get computed when you ask for them. uh unless they're already known or unless it's a repeat of a prior value. So or I should say the the very prior value. Um we can in this case set up a problem. Uh this is just the simple harmonic oscillator again, but now we're adding a variable for frequency. And we're going to also parameterize the initial slope
of the solution. And we just declare parameters here A and B as our parameters and ask for a solution. And we get this back. Okay. So if we try and comput a solution right away, it's not going to let us because it's saying, well, hey, we've got A and B. We don't know what they are. um you can ask what the parameters for problem are and you can set them uh in this way and now when we ask for a solution at one it's fine and it's computed with those values okay we can also obtain a plot um just using OD plot just as before uh for this solution so these were our parameter values we can change them and then we can see that okay once we change
The solution procedure we're currently working with has now been modified so that it's using the new parameter values and any computations performed will be at those parameter values. Okay, larger problems. Um this is where it gets more interesting. So if you have a very large problem, parameterization can be really handy, especially combined with compile. So I'm parameterized the problem here, uh, but I'm not using compile and I did essentially
um 100 calls with different values of the parameters integrating out to a thousand and it takes a certain amount of time in this case 084 seconds. This is a small problem. larger problems you'll see much larger times. So we do the same thing with compile now and we can see it's significantly faster. Um thing to keep in mind is this is a really simple function. I mean the the evaluations when you do the right hand side evaluation are going to just be the square and a product um to evaluate. So just compiling that part the core engine uh the actual integration engine already compiled code. Uh but now when it's compiled code using a compiled uh right hand side prop it's significantly faster. So this is going to be really handy for parameter searching and and those type of things. So compile is really really relevant here. Okay. Now interactivity. What can we do? Uh what what can we do interactively with the procedure? Uh you've seen a few
um up above we can ask how many evaluations we had to do. We can ask how many events or how many times events have fired when the last event is fired. We can ask what parameter values we're currently working with or what the parameters of the problem are. But there are a lot more. Um, we can ask what method was used to solve for the OD. We can query and set the initial values used for the OD. We can ask for the last value computed for the OD. Uh, a lot of event control
stuff as well and array. You might have briefly seen in Jurgen's presentation yesterday use of uh data array output and I'll show that here too. So, a few examples of this. Um, I've got a pretty loaded example here. Uh, so it's got um parameters um using events. Um, and I'm using a stiff solver and compiling. So, this gives us our procedure back. Uh, we can ask what's the method and it tells us it use Rosenbrook. Current initial conditions. uh y at 0 is zero. y prime at
zero is b. Last value computed. Well, we haven't called anything yet. So there's nothing. So now if we do an evaluation, wait, we haven't set the parameters. Okay, we'll set the parameters. Ah, and I I see a question um from is it nater J? Uh he recently changed to using a compiler that is shipped with part of Maple. Are you working with 2025 or an earlier version of Maple? Uh compilation in early versions of Maple on Windows requires setting up MSVC,
but that's no longer required at this time. Uh for newer versions of Maple, we have a variant of GCC that ships with Maple now. Um okay, so compile in more recent versions of Maple will work right out of the box. Um so we request the value at 100. we get a value. Now we ask for last. It tells us what the last value it computed was. We can clear the event. Um so we notice that it actually halted when we asked for the value at 100 at 3.14. Um and again
this is one of the places where last is handy. We can clear the event to say okay let's clear that halt trigger and continue integration. And if we do the clear and then we call it again, it runs until the next event occurs and so on. We can clear that and ask for it again and it goes until the next time the event occurs. This is really handy if you have um an integration that you want to do where you're performing the integration and you want to be
able to update or get the information at a very specific interval. You can set an event to hold and have it running in real time alongside some other computation if you need. Uh handy thing here explore. Um you want to integrate the parameter options with explore. I'm not sure. I haven't used explore that much. Uh I'd have to look and get back to you on that. So, somebody asked if one can integrate the parameters option with explore. I don't think it currently is, but um I I'll take
a look at that after and see. Uh at the moment, the parameters option works with the interactive dessol. Um uh so parameters are automatically handled there and that acts a bit like explore, but it's not the actual explorer command. Um, continuing with this example, we can turn that event off entirely and just say disable it. And now what happens is it runs as though you'd never specified the event to begin with. You can again ask how many function evaluations. Now the
uh new to Maple 2025 uh is the array feature. If you call with just array and nothing else and I'm using the string array here because array is a reserved word it's a command. Um it will tell you okay if you ask for array output these are the columns you're going to get t y of t y prime a and b and we included the parameters just so that one can't uh get confused about a data set. So now if we ask for array output and this is a little bit of a tricky specification is described
in the help. We're going to integrate out to 10 and we want 101 points and this is the notation we currently use for that. Um so I chose 101 because it will give us nice easy divisions of uh for 101 points out to 10 and we get the output here. And so this can this output can then be used uh as input to other things. Um can be saved uh and there's a question when can when do you apply the command DSN event disable? Um when
you disable the event it essentially just tells the integrator turn the event off but resume from start. So it's actually going to reintegrate from the beginning when you turn the event off at this time. Okay. So we've got this data. Uh now if anybody attended Dave's plot structure um stuff, you'll see that you know it's often easy to just call plot with, you know, simple data structures. And so I'm just extracting
uh the result all columns or I should should say all rows columns 0 and one and I have to cast that into a matrix because otherwise if I just ask for 01 it's indexed from zero and it wants the one and two. So if I can I can just call this simple command to directly display the plot without having to go through OD plot or anything else. Okay. Um all right. So I'm going to just briefly pause here if there are
any questions on this section for interactivity the um parameters compile and such. Okay. I see a question. Is there a simple method to change the parameters in OD on events? Um, okay. So, the easiest way to do that, um, if you want an a parameter to be changeable in an event is to make it a discrete variable instead. Um so because technically speaking if it's changing during the simulation it's it's more of a variable than a parameter. So you can declare
u you can declare the variable as discrete set the initial value to whatever you want it to start at and then have the event uh assign a different value. So where was that example? Where's my discrete? Oh, that would be in advance. Okay. Right. Okay. So, what we're going to do is we're going to add in um uh f of t here. Okay. And we're going to declare it. Okay, we're going to set an initial value. We'll start it at one. And we're going to change this around uh to say, okay, when y of t is 2, instead of doing this, we're going to set f of t is 10. All right, let's make sure I've done that right. So, we start off at a frequency of one. Uh,
we don't need num reset anymore because I've gotten rid of it. Okay. And there. Oh dear. Uh, why is this Not sure why it's discrete variables I declared. H sure I was working with this once. Um let me get back to you on this example. I'm not sure why this isn't working. Um this uh Cash, can you make a note and I'll get back to the person. Thanks. We'll do. There's a couple more questions. Okay. Fire away. Take a look at. Um, so Arthur asks, "Using ST to compute times is all well and good. How about time to find parameters in the help facility? Is it substantial?
I'm not sure I understand the question. Um, st. Arthur, do you want to um uh take yourself off mute and speak that would be fine. Or if you could elaborate in the chat. In the meantime, uh David is asking, I am currently looking at events uh help page and could you explain some of the options like to begin I am also interested in conditional triggers. How do they work? Okay. Well, to begin to end all those other things, they're they're related to state machine. So,
what you do is when you create a state machine, you define a discrete set of equations that run. Uh what you can do is uh and they'll run in exactly the order you specify them in the list. Um so when you say to begin uh that basically means that once you hit this specific action that has a two begin you bounce back to the very start of the set of discrete equations to evaluate to end jumps you to the end. And basically you have to think of things in terms
of that framework. And for conditional triggers um let me find a good example here to start. Uh for conditional triggers, you just define um I think there's an example in the help page, but you just have to define the condition combined with the trigger. Let me pull up the help. See? Oh no, that won't work because I'm sharing screen. Um yeah. uh you you just need to there is as I recall an example on the help page
uh that does a conditional trigger but conditional trigger um I saw a presentation um over the conference where there was a specific condition um that needed to be met was being met in two places but only one of them was the one of interest and uh you'd be able to set the conditional for that trigger so that only the one of interest would be specified. Okay, Arthur. So I see the Arthur's the actual time to solve the OD is trivial compared to the
time to find the word parameter in the help pages. Um, do you hear me? Yes, I do. Okay. So my point is that when you want to do some research and you're solving a problem, you start with the problem and then you have to look up how to use parameters. It's not obvious. In fact, it's a bit subtle. Okay? If you go to the help pages and look for parameter, you won't find it for quite a while. It's buried very very deep and you have to be very specific. And if you go to the desolve
numeric page, you still have to dig deeper. Those things are not obvious. I think what you need is someone who's not familiar with Maple to try to solve problems and then the difference between setting up parameters via the newer method rather than the old method of just using a procedure. While it's much much better, it really does have to be explained and it has findable. So perhaps a
a front front-facing dol numeric parameters help page would be in order and so that even searching just on parameters you would see it. Yes. Okay, that's a suggestion that um that I can definitely do. I will I will be I will have that on my list. Okay. But yeah, I did act. Yeah, it's we we want people to be able to see this so that they can use it for sure. And by the way, the explore function
is fantastic, but it would be very nice if it could be integrated with solving ODS. Yeah, I can I can look at that. Uh I'm not as like I said, I'm not as familiar with the explorer, but I will I'll take a look. Good. Thank you. Thank you. And Alan, while you're at it, uh David also commented that maybe uh dolve events need some better examples. Okay. Um all right. Uh I will definitely also put that on the list. Um yeah, it's it's a fine line between too many and and too few, but uh I will definitely add several uh for the events, especially in context of okay, let's make it easy to see exactly how to put a conditional on it. And uh probably Yeah, something better. But you can get really involved with state machines and the examples can become very long very fast. But uh yeah, by all means, I'm happy to add examples. Yeah, good. Any further comments on that section?
Okay, we'll move on to parameter optimization. Okay, I'm just giving a couple examples of parameter optimization. Um, so we have a parameterized OD here with y at 0 is one and our question is find a so that y at one is two. So it's pretty straightforward problem. So we just define our problem with the parameters. As always I'm using compile is true. Now this is uh a little tricky bit of code. Uh so I'm going to define an objective function. Okay, that takes in a parameter value and essentially uses this
solution procedure directly which I've declared as global because it's outside and I call it and set the parameter and then I just return the value of y at one. So small bit of glue code subtle but um it's not that difficult when you get the hang of it and I can say well okay if I now call this with 1/2 this sets the parameter to half does the integration out to one gives me the value at one
and there it is. Now that you've set this up to be a simple single input single output type process, you can now call it with fsolve directly. So you can say fsolve objective of x is 2 and uh get a value. We can set it and check it. And there we are. So this is a good way of being able to use a dolved numeric procedure directly in an objective function uh for optimization and we just look at the plot of this but it's pretty straightforward 0 to2 exactly what's expected. So this is a quite a toy problem. Um okay a little bit more complicated. I'm going to use the damped harmonic oscillator as an example. So this is our equation here. Mass the uh damping
constant and the spring constant are all inputs are part are all parameters of this equation. But we're going to look at a specific problem and say find the value of the damping constant so that the harmonic oscillation um damps as fast as possible. if we're measuring the energy with uh 1 eus 6 resolution and so that sensor would say that the oscillations would stop in the shortest amount of time. Okay. Uh for simplicity, we're just going to set K&M to one. You can come up with the kinetic and potential energy, which is what we're going to measure. uh this is our OD that we described up there with the M and K parameters evaluated out and now we're just going to call this uh dolve with this OD appropriate set of initial conditions specifying the parameters we're going to set tolerances of 1us 10 for absolute and relative error ask for it to be compiled and we're going
to define an event that says that when the sum of the energy is 1 - 6 volt. Okay. So we call this and just to test it we set parameters to one try and integrate out to 100 and we can see that okay at 13.2 event one triggered a halt. Um and this was the value of time and the position and velocity at that time and we could check it and it'll come on as 1 - 6. So again glue code um another nice optimization procedure. Uh I'm using this I'm sure it was documented but I
couldn't find it. slide was this is going to be documented in the next release which is simply simply a environment variable you can use to turn this warning off because if you're calling this repeatedly you don't want to see that coming up a lot. So this is otherwise quite similar to the prior uh optimization we had. So what do we do? We're taking in the parameter value. We're calling d solve setting that parameter value. We're computing that to 100 and we're returning
um in this case the time value right hand side of the first part of the result. Okay. So we can plot our optimizing procedure here between one and three and we see this um so we see that it's a bit non-trivial for the values to the left of the minimum but it's a lot smoother on the right. Uh this is important to look at because um minimize and fsol find local solutions. So if we actually started our solution somewhere in this
region around around 1.5 the value we would get would be uh not the minimum but the local minimum. So to avoid this, we're calling minimize with a given range that doesn't include that minima and we get our value um and optimize gives the the objective function value and the parameter value at which that occurred. So at 1.81 we get our minimum of 6.88. Now those familiar with the this problem uh might know that uh in practical terms the optimal value for C
um is is for something called critical damping where the damping occurs as rapidly as possible is in fact two normally but we see that that's not actually the minimum here because we have the additional consider consideration that we only need to get down to 1 minus 6, not all the way to exactly zero. So we're asking for the measurability as opposed to the precise value. And that gives us this. So there any questions on that um parameter optimization and such at this point?
No. Okay. Oh, why ob? Ah yes. Okay. Um why the unevaluation quotes? Uh where was that? Um okay. So we're using that evaluation quotes to prevent it from attempting to evaluate at um a value that isn't numeric yet. So let's see here. Where is the Oh, this one. This is the one with OB. Okay. Yeah. So, here we ask for OB. Let's redefine this again just to be sure we've got it. We ask for objective of
X where X isn't specified. We get an error um that says that hey, it's supposed to be numeric. By putting the unevaluation quotes around it, we say we delay evaluation. And by sending that to fsolve, we delay evaluation until fsolve chooses a value for x. So it's going to use different values of x to compute it. But it's never going to try and compute it with just x, which is going to result in the error I just showed here. Okay.
All right. Um I'm going to move on to the next part. Boundary value problems. Okay. The BVP solver. Um let's look at a simple case first. Uh this is a case with some mild boundary layers. Um so we have just yp prime minus 1,000 y is zero. Initial condition or boundary conditions one at either end. Ask for the solution and look for the plot. Okay. So as I mentioned this has some very relaxed boundary layers at either end or the or this DV. Um the larger this value here, the 1,00 the tighter the boundary layers become.
Okay. Uh this is a good one. Um I think I briefly mentioned this yesterday uh in the talk, but we handle singular uh coefficient problems on either end. Um this is really handy for especially for problems that have come from spherical or polar coordinates and are a um reduction of variables. Um so that because typically the radius occurs in the denominator in a lot of cases. Um so in this one the mden equation this is coming from spherical
coordinates and this is the de we're trying to sol or boundary value problem we're trying to solve here. Okay. So um you're going to have a problem at r equals z just directly evaluating this. So you need something that can actually handle that singularity. Okay. So we set our boundary conditions. uh the boundary condition at the left is uh specific value for y and the boundary condition at the right is a zero slope condition.
Okay. So when we try and solve this directly um with d numeric it complains and says that you need to use a midpoint method there. This is described in the help page. Um so we can use one of the two available midpoint methods. In this case, I'm just using mid defer and obtain a solution. And then we can look at the plot. And it looks pretty pretty nice and smooth. You can't really tell that there's a problem at the origin. If we compare to the exact solution,
uh we can see that we get very reasonable. And I chose these specific initial and boundary value problems because there happened to be an exact solution for those so that we could verify. And so we see that we get very reasonable um accuracy here uh out to 6US 8. Uh the default I believe for boundary value problem is 1 - 6. Uh we can ask for tighter tolerances. Um just simply specifying abs there. Unlike init uh unlike um initial value problem integration only absolute
error is used not relative error uh for the boundary value problem solver. So you only need to specify the one and we can look at that solution. We can see that yeah we get a tighter and more accurate solution with the higher to tighter tolerances as expected. Okay. All right. Now, um I had to look around a bit to find a really nice challenging boundary value problem and I saw found this one. There was a interesting YouTube video on this one where
um somebody went to all sorts of interesting links to figure out how to actually solve this problem. Uh including um flow diagrams like deplot. uh if you were around for yesterday's presentation to see, you know, what we expect to come out. But as a problem, it's tough because we've got the the leading derivative has a very very small coefficient and uh there's nonlinearity. So it's a kind of a double whammy. Um we have initial conditions of one at zero and minus one at one.
And if we try to solve this directly, we have a problem. And um this this is the initial Newton iteration is not converging. What do I do? Like uh you know how how would I attack this? Uh but you have to come to some at least a mild understanding of the problem and say okay well I think the main problem is this tiny coefficient here. Okay. So what would happen if uh we parameterized that coefficient and chose an easier value for it like one and if we do there's no problem
at all solved again it okay what about one10th same 180th same so we can see that okay so yes um smaller values of the parameter that is the problem solution can easil easily be obtained with uh a larger value for that coefficient. Okay. And we can also see is as we're making that coefficient smaller and smaller there becomes this um boundary layer in the middle of the um region. So now we try and go a little bit smaller 1 over 160 and we get a complaint and it says well I
couldn't get the requested accuracy with 128 point mesh was able to get this. Consider increasing max mesh or using a larger absolute error. Okay well we we want to keep our error tolerance the same. So we're going to bump up max mesh uh to say 512. And now we get a solution. Okay, we're not there yet because we're we're almost at 10. We're a little over 10% of the way there. Let's bump it all the way up to one over 500. And we're back to the original problem. Okay, it can't get it even with a reasonably large value of a max mesh. So, how are we going to do this? Um, this is where continuation comes in handy. Okay, continuation. I have used continuation to solve all sorts of um problems. In this case, it's a case where it's a small coefficient. So, it's actually just jumping out at you what what value you would want to transition to get to a solution. But in many
cases, you have you might have a nasty nonlinear OD and uh you don't necessarily know. is there's nothing that jumps out at you and says, "Yeah, this is what you want to use continuation on." And in many cases, it's a bit of trial and error, but I've often found that small coefficients and particularly nasty nonlinear terms that can be converted to linear locally, you can do a continuation that moves from the linear to the more nonlinear problem, from the large uh from a
larger coefficient to a smaller coefficient. And you can actually do the two of those simultaneously with the same parameter. and I've gotten solutions out quite straightforwardly just using continuation in that way. So we're going to do a continuation here. Um so what I've done is I've created a value for epsilon so that when p is zero which is where you start your continuation you get one and when p is one which is the end of the continuation you get the target od the
thing you want to solve. Okay so we define this we can just double check did we do this right? Yeah. Okay, so the OD uh for p=0 is the simple one we know is really easy to solve and for the p= 1 is the one we want to solve. Okay, so we try to use continuation with the 512 point mesh. And now it tells us, oh, okay, mesh size too few mesh points. So increase it. And if we do, we get our solution.
And you can see this is an extremely sharp interior boundary layer that we've just managed to resolve using continuation. Continuation is a very powerful tool for finding OD solutions, but it definitely requires some degree of trial and error and human interaction to figure out what a good continuation is. Okay. So, are there any questions on boundary value problem solving? Not at this time. Okay. If anybody has a question on it um or something occurs to you,
you can feel free to ask it at the end and we can cover it then. Okay. Uh something that I know is near and dear to definitely the hearts of a couple of people attending today. Igen function and igen values. Um there are two basic approaches one better than the other usually uh forg value problems. Um so we're going to do a simple value problem to start and then we're going to move on to a more complicated example um second. So the first one
is just to get a feel for okay what can we do? Um so the first standard igen value problem this is probably the first igen value problem that people see in a course is good old wave equation um where we have um y prime + c ^2 y is zero and conditions of y is zero on the left and y is zero on the right. This naturally admits the zero solution which is very uninteresting. So there are going to be solutions for discrete values of C and we want to try and find these. Okay, several
of you are probably familiar with shooting. Okay, so the shooting approach, we make C an unknown parameter and we choose a value for Y prime at zero to get normalization. This is to avoid that zero solution specifically. Okay. And we're going to search for C values that give y at one is zero. In other words, match our second condition here. Okay. So we define our shooting system as an initial value problem where the parameter C is free and we have two initial conditions.
So we set this up using d of numeric parameters. Again we form another objective function. Okay. And we can plot the objective function to see okay this is C. Okay. And we see that we get a zero. Oh I should mention yeah. So what this objective function is is it's taking the parameter value in and giving the value at x= 1 out. So what we're looking for here is a c value where we're getting a zero. And we can see here a little past three a little past six um between

Ask anything
We've read this whole study set, so questions about it get the best answers.