I have two differential equations:

R * (dVi/dt) + (1/C) * Vi + P0 = P1 , 0<=t<=t[i]
R * (dVe/dt) + (1/C) * Ve + P0 = 0 , t[i]<=t<=t[tot]

With some help I solved the first one

ClearAll[Vi, t, C0, p0, p1, R0];
ode = R0*Vi'[t] + (1/C0)*Vi[t] + p0 == p1
ic = Vi[0] == 0
sol = DSolve[{ode, ic}, Vi[t], t]

But the second one has as initial condition


I tries to solved it like this knowing that Ve(t[tot])=0 but it doesn't work

ode2 = R0*Ve'[t] + (1/C0)*Ve[t] + p0 == 0
ic2 = Ve[t] == Vi[t]
sol2 = NDSolve[{ode2, ic2}, Ve[t], {t, sol, 0}]
  • $\begingroup$ Initial conditions can't really be written as ic2 = Ve[t] == Vi[t]. You need to give it a specific value at some specific time. may be ic2 = Ve[0] == Vi[0] or something like this. I also do not understand Ve(t[i])=Vi(t[i]) what is i here? $\endgroup$ – Nasser Nov 19 '17 at 0:08
  • $\begingroup$ @Nasser i didn't write it right, I shouldn't write it as t[i] just ti which is a moment in time . I have two intervals, [0,ti] and [ti,ttot] $\endgroup$ – Darius Ionut Nov 19 '17 at 0:33
  • $\begingroup$ Well, when you solve an ODE by hand, the constant of integration is found from initial conditions. So you need to give some specific time value. Something like Ve[5]==someValue, Otherwise, I am not sure how giving an interval is going to work. I never seen an ODE solved using interval for initial conditions. $\endgroup$ – Nasser Nov 19 '17 at 0:36
  • $\begingroup$ @Nasser cit-evolution.weebly.com/uploads/6/8/9/8/6898684/… the problem is at page 99 in the pdf, if you have some time to look at it, maybe I don't understant the text enought but I relly don't know how to write it $\endgroup$ – Darius Ionut Nov 19 '17 at 0:45
  • $\begingroup$ @DariusIonut two struggling things: 1.- there is no problem like this one you are asking for help in p. 99 of the book you mention. 2.- how is possible that the second ODE solution will evolve from a time t[i] to 0 ({t, sol ,0})? $\endgroup$ – José Antonio Díaz Navas Nov 19 '17 at 17:46

You have to use the output of the first ODE at time ti as the initial condition for the second ODE.

ODE #1

  p0 + vi[t]/c0 + r0 Derivative[1][vi][t] == p1,
  vi[0] == 0

(* -c0 E^(-(t/(c0 r0))) (-1 + E^(t/(c0 r0))) (p0 - p1) *)

Now we use the answer to define vi[t].

vi[t_] := -c0 E^(-(t/(c0 r0))) (-1 + E^(t/(c0 r0))) (p0 - p1)

We evaluate it at time ti to be used as the initial condition for the second ODE.


(* -c0 E^(-(ti/(c0 r0))) (-1 + E^(ti/(c0 r0))) (p0 - p1) *)

ODE #2

We use the value of vi[ti] as the initial condition in the second ODE.

  p0 + ve[t]/c0 + r0 Derivative[1][ve][t] == 0,
  ve[ti] == -c0 E^(-(ti/(c0 r0))) (-1 + E^(ti/(c0 r0))) (p0 - p1)
(* -c0 E^(-(t/(c0 r0))) (-p0 + E^(t/(c0 r0)) p0 + p1 - E^(ti/(c0 r0)) p1) *)

and use the answer to define the function ve[t]

ve[t_] := -c0 E^(-(t/(c0 r0))) (-p0 + E^(t/(c0 r0)) p0 + p1 - E^(ti/(c0 r0)) p1)

Now combine the two functions into one (a voltage?).

v[t_] := Piecewise[{
   {vi[t], t <= ti}

Set some values for the parameters and plot the result.

r0 = 5;

p0 = 1;

c0 = 1;

p1 = 3;

ti = 1;

Plot[v[t], {t, 0, 2}, PlotStyle -> Black]

Mathematica graphics

| improve this answer | |

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.