0

Hi~ I'm learning using shootig method to solve a differential equation with boundary condition. The problem is (from Sauer textbook):

enter image description here

function z=F(s)
a=0;b=1;yb=3;
ydot=@(t,y) [y(2);4*y(1)];
[t,y]=ode45(ydot,[a,b],[1,s]);
z=y(end,1)-yb; % end means last entry of solution y

My question is about "ydot=@(t,y) [y(2);4*y(1)];". I know it's a function handle. But what is y(2) and y(1) here? I've seen function handle with parentheses. Why we have square brackets here?

Claire Sun
  • 23
  • 2
  • 1
    you have to give to the function a vector with at least 2 entries. lets say `y=[3;4]` then `y(1)` is 3 and `y(2)` is 4. The return value of `ydot` is again a vector, therefore you have to but square brackets around it. For [3;4] as input the returnvalue should be [4;12] . But i feel like there might be something missing here. `ydot`also wants a `t` but the value is unused. Are you sure it has to be there too? – Finn Oct 10 '18 at 06:36

1 Answers1

0

Because every ODE can be transformed into an system of ODEs of first order, nearly all ODE solvers require a transformation into a first order ODE before you pass the right hand side of your ODE.

For your second order ODE y''=4y set y_1 = y and y_2 = y'. Then y_1' = y' = y_2 and y_2' = y'' = 4y_1. Now you can write:

enter image description here

Now it's clear that your function handle is just the right hand side of this first order ODE.

joni
  • 6,840
  • 2
  • 13
  • 20