I am trying to solve an ode with an unknown parameter. I am not sure If I am doing it in the right way. 'Not enough input arguments'
tol = 10^-3; % Treshold
MAX = 100;
H = 0;
interval = [0.01 0.2]; % alpha interval
a = interval(1);
b = interval(2);
alpha = (a+b)/2;
v0=[1 0.01 1];
[z,v]=ode45(@rhs,interval,v0,alpha);
iter = 1;
while(abs((v(end, 2)) - H) > tol)
alpha= (a + b)/2;
[z,v]=ode45(@rhs,zspan,v0,alpha);
end
if(v(end, 2) - H > 0)
b = alpha;
else
a = alpha;
end
iter = iter + 1;
if(iter > MAX)
return;
end
function parameters=rhs(z,v,alpha)
da= 2*alpha-(v(1).*v(3))./(2*v(2).^2);
db= (v(3)./v(2))-(2*alpha*v(2)./v(1));
dc= -(2*alpha*v(3)./v(1));
parameters=[da;db;dc];
end

 採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 7 日

0 投票

4 件のコメント

Dereje
Dereje 2018 年 4 月 7 日
Hi Walter, The document in the link has no helpful info for the purpose of my case.
Steven Lord
Steven Lord 2018 年 4 月 7 日
That page describes how you can pass the variable alpha defined in your script into the rhs function whose function handle you pass into ode45.
Walter Roberson
Walter Roberson 2018 年 4 月 7 日
[z,v]=ode45(@(z,v)rhs(z,v,alpha),zspan,v0);
Notice that @(z,v)rhs(z,v,alpha) is an example of parameterizing a function just like is described in the link.
Dereje
Dereje 2018 年 4 月 7 日
I see it now. The code works as well as intended. Thanks a lot!!

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

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2018 年 4 月 7 日

コメント済み:

2018 年 4 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by