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)];

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by