简体   繁体   中英

function handle in matlab

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

在此处输入图片说明

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?

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:

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM