Solve differential equation with anonymous functions

4 ビュー (過去 30 日間)
Walter Sanchez
Walter Sanchez 2017 年 9 月 23 日
コメント済み: Walter Sanchez 2017 年 9 月 23 日
Hello, everyone. I am already quite familiar when it comes to the resolution of differential equations(DE’S) in MATLAB with “ode45” function. I have already solved this problem by making a function dFdV that contained the DE’S which has as inputs (V,F), being V the independent and F the dependent variable.
function dFdV=funcion(V,F)
CTo=0.286;
k=0.4;
FT=F(1)+F(2)+F(3); % FT=FA+FB+FC;
CA=(CTo*F(1))/FT;
rA=-k*CA^2;
rB=-rA;
rC=-0.5*rA;
dFdV=zeros(3,1);
dFdV(1)=rA;
dFdV(2)=rB;
dFdV(3)=rC;
end
What I now want is to solve the same problem creating an anonymous function that contains the DE’S and using again “ode45” to solve them.
CTo=0.286;
k=0.4;
FT=@(F)(F(1)+F(2)+F(3)); % FT=FA+FB+FC;
CA=@(F)((CTo*F(1))/FT(F));
rA=-k*(CA(F))^2;
rB=-rA;
rC=-0.5*rA;
dFdV=@(V,F)[rA;rB;rC];
The problem is that when executing It pops up this message (“Undefined function or variable 'F'), which is obvious because now my function dFdV depends on V and F, but F has not been defined (as an input) as the former case.
What should I do?. Thanks

採用された回答

Walter Roberson
Walter Roberson 2017 年 9 月 23 日
CTo=0.286;
k=0.4;
FT=@(F)(F(1)+F(2)+F(3)); % FT=FA+FB+FC;
CA=@(F)((CTo*F(1))/FT(F));
rA=@(F) -k*(CA(F))^2;
rB=@(F)-rA(F);
rC=@(F)-0.5*rA(F);
dFdV=@(V,F)[rA(F);rB(F);rC(F)];
  1 件のコメント
Walter Sanchez
Walter Sanchez 2017 年 9 月 23 日
Thanks, Walter. It worked right away.

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

その他の回答 (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