# NDSolve does not satisfy initial conditions

For the problem I'm facing, I have three coupled diff eqns that I'm trying to solve

ClearAll["Global*"]
i = 4;
R2 = 0.001;
RL = 100000;
RS = 100000000;
R1 = 0.04834;
C1 = 8.48;
C2 = 3.44;
s = NDSolve[{V1[t] == RS/(RS + R1)*V2[t] + RS*R1*i/(RS + R1),
V2'[t] ==
1/C1*(i R2 RL RS - (R2 RL + R1 (R2 + RL) + (R2 + RL) RS) V2[t] +
RL (R1 + RS) V3[t])/(R2 RL (R1 + RS)),
V3'[t] == 1/C2*(V2[t] - V3[t])/R2, V2[0] == 0,
V1[0] == RS*R1*i/(RS + R1), V3[0] == 0}, V1, {t, 0, 5}]


I set V1[0]==RS*R1*i/(RS + R1) which actually equals aprrox 0.19, but when i plot V1[t] the intercept is ~0.12.

• When I run your code, I get a solution where V1[0] = 0.19336 (evaluate V1[0] /. First[s].) This shows the same way on the graph. Can you provide a copy of your output? Knowing which Mathematica version and operating system you're using might also be helpful. – Michael Seifert Aug 17 '15 at 15:21
• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. – bbgodfrey Aug 17 '15 at 16:29
• Thanks for the confirmation. I found that the issue was because of carry over variables. I closed mathematica and copied the code in and now the results are fine. How can I avoid this in the future. I thought that ClearAll["Global*"] would prevent this – jerry Aug 17 '15 at 16:57

This system can be solved exactly with DSolve

\$Version


"10.2.0 for Mac OS X x86 (64-bit) (July 7, 2015)"

ClearAll["Global*"]
i = 4;
R2 = 0.001 // Rationalize;
RL = 100000;
RS = 100000000;
R1 = 0.04834 // Rationalize;
C1 = 8.48 // Rationalize;
C2 = 3.44 // Rationalize;

s = DSolve[{V1[t] == RS/(RS + R1)*V2[t] + RS*R1*i/(RS + R1),
V2'[t] ==
1/C1*(i R2 RL RS - (R2 RL + R1 (R2 + RL) + (R2 + RL) RS) V2[t] +
RL (R1 + RS) V3[t])/(R2 RL (R1 + RS)),
V3'[t] == 1/C2*(V2[t] - V3[t])/R2, V2[0] == 0,
V1[0] == RS*R1*i/(RS + R1), V3[0] == 0}, {V1[t], V2[t], V3[t]}, t][[1]];

V1[t] /. s /. t -> 0.


0.19336

Plot[
Evaluate[{V1[t], V2[t], V3[t]} /. s],
{t, 0, 5},
PlotStyle -> {Blue, {Green, Thick}, {Red, AbsoluteDashing[{10, 10}]}},
PlotLegends -> {V1[t], V2[t], V3[t]}]


For t >= 0, V2 and V3 are very close to each other.

NMaximize[{Norm[V2[t] - V3[t]] /. s, t >= 0}, t]


{0.00115436, {t -> 0.0485123}}

• Wow thanks for the plot as well! – jerry Aug 17 '15 at 17:37
• For future reference, what is the benefit of using rationalize and what exactly does /. do in the code? I've only been using /. because i saw it in the mathematica sample. – jerry Aug 17 '15 at 17:44
• To get information about a function or operator, highlight (double-click) and then press F1` (Help) for documentation. – Bob Hanlon Aug 17 '15 at 17:49
• @jerry Exact solvers love exact coefficients. – Michael E2 Aug 17 '15 at 22:53