Using ode 45 for the shooting method

1 回表示 (過去 30 日間)
Johnson
Johnson 2014 年 12 月 28 日
編集済み: Johnson 2014 年 12 月 29 日
Dear experts,
I'm given a system of ODE's that I am able to solve using "ode45" . The system contains several initial conditions, and I am mainly interested in one of them - "k" . I want to find the value of "k" for which one of the variables (which I shall call "u") is 0 at x=20.
I have tried the following ( I give only the important parts of the code):
1. function uTWENTY=check(k)
[X,Y]=ode45(@... , [0 20] ,[... k ... ] )
uTWENTY=Y(end,4); %assuming Y(:,4) = u
end
2. function shooting
correctK=fzero(check,[0.001,1]);
%I want somewhere inside this interval 0.001,1] there must be a correct value of k
end
Unfortunately, I always get the same error: "Reference to a cleared variable k"
Will someone please help me understand how to ask MATLAB to solve "check" inside the interval [0.001,1] (where the unknown is k)?
Thanks in advance!

採用された回答

Jan
Jan 2014 年 12 月 28 日
Do you mean:
correctK = fzero(@check, [0.001, 1]);
  1 件のコメント
Johnson
Johnson 2014 年 12 月 29 日
編集済み: Johnson 2014 年 12 月 29 日
An Update : It worked ! (In addition to deleting the "clear all " at the start of the second function :) )
Thanks a lot !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by