Hi all,
I need help solving two first order differential equations.
dphi=(akd).*((exp(-(phi)))-(exp(psi)));
dpsi=(epp)-(exp(psi))-((ba).*(dphi));
epp ba and akd are defined. Phi and Psi are my variables, where dphi is the derivative with respect to t and dpsi is the derivative with respect to t. I tried perusing the help files but cannot get it to work. We were advised to use ode15s.
I tried making the equations into a vector field to put into the function but also struggled with this. Sidenote; dphi can be substituted in the dpsi equation.
Thanks.

댓글 수: 3

James Tursa
James Tursa 2018년 10월 5일
Please post what you have tried so far and then we can give suggestions and comments on how to fix your code etc.
James Bader
James Bader 2018년 10월 5일
%u=[-1,1;-1,1]; epp=(exp(1)); ba=.5; akd=1.5;
%Y(1)=phi, Y(2)=psi
syms phi(t) psi(t)
ode1= diff(phi) == (akd).*((exp(-(phi)))-(exp(psi))); ode2= diff(psi) == (epp)-(exp(psi))-((ba).*(akd).*((exp(-(phi)))-(exp(psi))));
[V]= odeToVectorField(ode1,ode2);
F=@(phi,psi,t)[V];
sol = ode15s(F,[0 20], [.1 .1]);
James Bader
James Bader 2018년 10월 5일
Error using odearguments (line 113) Inputs must be floats, namely single or double.
Error in ode15s (line 150) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in RSDFevolve (line 27) sol = ode15s(F,[0 20], [.1 .1]);
This is the error message I receive.

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephan
Stephan 2018년 10월 5일
편집: Stephan 2018년 10월 5일

0 개 추천

Hi,
you missed to make a function handle from your vector field like shown here - psi(t) and phi(t) are still symbolic in your function handle, this is the problem you have.
Try:
syms phi(t) psi(t) epp akd ba
eqn1 = (akd).*((exp(-(phi)))-(exp(psi))) == diff(phi,t);
eqn2 = (epp)-(exp(psi))-((ba).*diff(phi,t)) == diff(psi,t);
eqn = [eqn1 eqn2];
eqn = subs(eqn,[epp ba akd], [exp(1), 5, 1.5]);
V = odeToVectorField(eqn);
M = matlabFunction(V, 'vars', {'t','Y'});
y0 = [0.1, 0.1];
tspan = [0 20];
[t,y] = ode15s(M, tspan, y0);
plot(t,y(:,1),t,y(:,2))

댓글 수: 1

James Bader
James Bader 2018년 10월 5일
Thanks! I see one issue was not making even my defined variables symbolic (bleh). Also that I wasn't quite defining these variables correctly in my equations.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2018년 10월 5일

댓글:

2018년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by