Help with two 1st order diff eq

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 个评论

Please post what you have tried so far and then we can give suggestions and comments on how to fix your code etc.
%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]);
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
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 个评论

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 个)

类别

Community Treasure Hunt

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

Start Hunting!

Translated by