Transcript for:
Tutorial on Solving Boundary Value Problems (BVPs)

hi everyone today we continue our series of tutorials on differential equations and in this episode we discuss boundary value problems previously we learned how to solve initial value problems you can check that tutorial and the link is in the description now i'm going to teach you the essential skills to solve a boundary value problem i try to go beyond simple problems and we discuss some creative stuff too so let's go i want to solve this equation with these boundary values you may remember from our previous tutorial that in order to solve a second order initial value problem our initial conditions contained one equation for y and another for y prime both at the beginning of time interval now for bbps you can see the equations are different to solve boundary value problems we use this solver bvp c i type help pvp for c and here is the general form of using this solver this solver can only have one output argument which we named sol here and it takes three arguments the equation the boundary condition and the initial guess the first argument is the system of equations which we defined using a function f the procedure is similar to ote45 command we have a second order equation so the states variables are going to be y and y prime so dsdt will be y prime and y double prime i define dsdt using my state variables of course y double prime is equal to negative exponential y next we should define the boundary conditions look at the boundary conditions we can understand that we want to solve from zero to one let's name the beginning of our interval a and the ending b i have one equation for a and one equation for b i write a header for my bc function it is the standard form and i advise you to keep it like this y a is a vector which contains y and y prime values at a y b is a vector containing y and y prime at b important note when you want to write the boundary conditions the right hand sides must be zero in our problem it is already satisfied but we will see other situations in another problem so our boundary values should be written like this output equal to the first argument of y a and the first argument of yb the third input argument is solinit this is the initial guess which we should provide for the solver and it needs an initializer named bvp in it soldering it equal to bvp in it so as the first argument i discretize the interval using linear space function i discretize 0 to 1 with 5 points now i should give a value to each of these points i can define the function for that or i can give all of them a constant value each point must have a value for y and the value for y prime i give all of them 0 for both of the values now i can run the code i take a look at sol it has x and y and y p which stands for y prime this is sold at x i had defined it here this is the solution for y and y prime and dot yp is again y prime and y double prime so i plot y versus x i can also add more points and run again i know that this equation has another solution too to find the other solution i must use a more complicated initial guess i use the same values for x but i defined a function for corresponding y and y prime values at each node i named the function guess i define it with one input and one output argument i know this parabola is similar to my answer since its value is zero at my boundaries i use this parabola and its derivative as the output now if i run it gives me the same answer i multiply my initial guess by 20 and this is the second solution next i want to solve this equation this is a first order equation with one unknown variable so we need one equation for the ode and one equation to find lambda these are the two boundary conditions for that matter i solved the problem and i hope you can follow the procedure with me the trick is to take my unknown variable to be y and lambda and dsdt will be y prime and lambda prime i know the equation for y prime and since lambda is a constant its derivative will be zero so i write the equations for boundary conditions this is a and this is b as i said the right hand side of my boundary condition equations must be zero so i rewrite the equations like this and this is going to be my output for the initial guess again i discretize my interval into 50 points and i use some initial guess for y and lambda and this is the solution and i also check lambda here it is my constant value i want to mention that for these special kinds of problems where we have one equation with one unknown parameter we can use bvp for c in a more advanced way here i define my equation but i add one more input argument matlab understands that this is a constant parameter then i must also add this constant to my bc y a and y b are no longer vectors they are simply the values for y at the boundaries also for my initial guess i must enter y and lambda separately to find lambda i write soul dot parameters and this is the plot thank you for watching if you enjoyed this tutorial i would be grateful if you like this video and subscribe to my channel bye bye