フィルターのクリア

Parameter that depends on a State Variable

1 回表示 (過去 30 日間)
Ghazwan
Ghazwan 2016 年 10 月 11 日
コメント済み: Ghazwan 2016 年 10 月 11 日
Hello, I have the following main code
clear all;
global a1 b1 c1 P0 Sr2
a1=0.01; b1= 4.13; c1=1.250; Sr2=24.83683
P0=5;
x0=35;
[tt,xa]=ode45(myodefun,[0:0.01:7],x0);
and the myodefun function is
function FF=myodefun(t,x)
global Ptr Sr2 a1 b1 c1
Ptr1=x-5.5;
Ptr=Ptr1;
fun = @ff1; % function
x0 = 2; % initial point
V1 = fzero(fun,x0);
R=Sr2./(V1.^2); C=1./(a1.*c1.*exp(c.*V1)+b1./V1);
FF=(2./(R.*C)).*(110-2.*x);
And the other ff1 function is
function y = ff1(V)
global a1 b1 c1 P0 Ptr
y = a1*exp(c1*V)+b1*log(c1*V)-P0-Ptr;
As you can see that V1 depends on the calculations of the state variable x. When I run the code, I get the following error:
Not enough input arguments.
Error in myodefun (line 5)
Ptr1=x-5.5;
Error in Out (line 6)
[tt,xa]=ode45(myodefun,[0:0.01:7],x0);
I can not find where the problem is! Even though I did it several time before for different problems! I do not know what it means by not enough input arguments.
Thanks in advance.

採用された回答

James Tursa
James Tursa 2016 年 10 月 11 日
編集済み: James Tursa 2016 年 10 月 11 日
In this line:
[tt,xa]=ode45(myodefun,[0:0.01:7],x0);
The 1st argument to ode45 is myodefun, which is a call to the function myodefun without any arguments. So when you get into myodefun and hit the line with the x, x was not passed in hence the error. To fix this, pass in a function handle to myodefun:
[tt,xa]=ode45(@myodefun,[0:0.01:7],x0);
  1 件のコメント
Ghazwan
Ghazwan 2016 年 10 月 11 日
Thank you James! It worked like magic!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by