I have the following set of equations:



$v_s(v,u)=b \left(\frac{1}{1+a(u,v)}-\frac{e^{-v}}{a(u,v)+e^{-v}}\right)$

$u_s(v,u)=b \left(\frac{e^{u}}{a(u,v)+e^{u}}-\frac{1}{1+a(u,v)}\right)$


with the following initial conditions:

$u(0)=u_0$, $v(0)=v_0$

I need to obtain $v_s$ and $u_s$ first for every step $t$, and then plug them in the differential equations of $\frac{dv}{dt},\frac{du}{dt}$.

Since $v_s$ and $u_s$ have a recursion relation I can't manage to write a script that will solve these equations.

This is what I've obtained so far:

a[v_, u_] := (1/u) (1 - E^(-v)) + (1/v) (1 - E^u);
vs[v_, u_] := b (1/(a[v, u] + 1) - (E^(-v)))/(E^(-v) + a[v, u]);
us[v_, u_] := b (E^u/(E^u + a[v, u]) - 1/(1 + a[v, u]));
b = 1; u0 = 1; v0 = 1;
NDSolve[{v'[t] == v[t] - vs[v[t], u[t]], u'[t] == u[t] - us[v[t], u[t]],
   v[0] == v0, u[0] == u0}, {v[t], u[t]}, {t, 0, 100}];

Full guidance or a scheme that will generalize this problem will be accepted as an answer.

  • 2
    $\begingroup$ I fixed some typos in your code (misplaced brackets, wrong syntax in NDSolve, use of Set (=) instead of Equal (==)). It still generates errors, but they now seem to be the errors you were asking about. $\endgroup$ Nov 11, 2017 at 11:48
  • $\begingroup$ After @aardvark2012's corrections, your code works up to t=41.5, so there isn't any problem with the definition of vs and us. $\endgroup$
    – Chris K
    Nov 11, 2017 at 19:40

1 Answer 1


If $u$ and $v$ depend on $t$, this must be set whenever they appears, if you do not want to define functions, unless you need them afterwards.

I have just retyped your code, and plot the solutions. Please, take a look, I am not sure what you are expecting though.

Just an additional note: the range for $t$ was shortened to avoid overflow in the calculations by NDSolve. I assume that you will take care of this in your application.

Hope this helps:

a = (1/u[t]) (1 - E^(-v[t])) + (1/v[t]) (1 - E^u[t]);
vs[t] = b (1/(a + 1) - (E^(-v[t])))/(E^(-v[t]) + a);
us[t] = b (E^u[t]/(E^u[t] + a) - 1/(1 + a));
b = 1;

sol = NDSolve[{v'[t] == v[t] - vs[t], u'[t] == u[t] - us[t], v[0] == 1, u[0] == 1}, {v[t], u[t]}, {t, 0, 40}];

{u[t], v[t]} = {u[t], v[t]} /. sol[[1]];
Plot[{u[t], v[t]}, {t, 0, 40}, PlotRange -> {0, 1000},PlotStyle -> {Blue, Red}, PlotLegends -> "Expressions"]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.