# Ideal transformer model (2 ODEs) warning “NDSolve will try solving the system as differential-algebraic equations”

I have a simple electrical circuit of an ideal transformer: I model it in Mathematica 11.3 with the idea to solve for secondary current and potential difference. Here is my code:

ClearAll["Global*"]

time = 0.001;

r1 = 0.5;
r2 = 1000;
l1 = 0.001;
l2 = 0.1;
m = Sqrt[l1*l2];

vSource[t_] = 20 Sin[10000*Pi* t];

eq1 = vSource[t] == i1[t]*r1 + l1*i1'[t] - m*i2'[t];
eq2 = m*i1'[t] == i2[t]*r2 + l2*i2'[t];

ic1 = i1 == 0;
ic2 = i2 == 0;

sol = NDSolveValue[{eq1, eq2, ic1, ic2}, i2, {t, 0, time}];
Plot[sol[t], {t, 0, time}, PlotLabel -> "Current through r2"]
Plot[sol[t]*r2, {t, 0, time}, PlotLabel -> "Potential difference across r2"]


And here is the plotted solution: which corresponds to my LTSpice solution:

Now my problem is that I get the following warning: Despite getting the solution, warning signifies that I am doing something wrong. Could anyone please help solve my problem properly and explain why I get the warning?

• If you try to bring {eq1,eq2} in an explicit form you'll recognize some problems. That's the error message MMA shows! – Ulrich Neumann Nov 14 '18 at 11:09
• The system of equations is degenerate because l1 l2 - m^2=0. Therefore Mathematica gives a warning. Do not pay attention, it is still a solution to the equations in this case. – Alex Trounev Nov 14 '18 at 11:36
• If you want the equations not to degenerate, you can write m = 0.99 Sqrt[l1 l2]. Then there is no warning anymore. The solver doesn't commute to the DAE Solver, which is a good thing because the DAE solver is not very robust (and useless in this case), and physically it is realistic. – andre314 Nov 14 '18 at 11:59
• @andre, that's a neat trick that makes sense physically. In fact, this solved my problem in SystemModeler. Unfortunately, I get weird results if I increase load resistance. Could you try to switch r2 to 1,000,000 and see what you get? – space bobcat Nov 14 '18 at 12:27
• @andre, please disregard my comment. I was receiving awkward result because I had AccuracyGoal set to a low value. In SystemModeler, unfortunately, my solution gets weird if I increase r2. – space bobcat Nov 14 '18 at 12:32

A warning only signifies that you may have done something wrong, but you've just done nothing wrong in this case. This can be verified by comparing the numeric solution with the analytic solution:

analyticsol = i2 /. DSolve[{eq1, eq2, ic1, ic2}, {i1, i2}, t][]

Plot[{analyticsol@t, sol[t]}, {t, 0, time}, PlotStyle -> {Automatic, {Red, Dashed}},
PlotLegends -> {"Analytic Solution", "Numeric Solution"}] So, why does the warning pop up? As already explained in the comments above, it's because NDSolve is trying to transform the ODE system to an explicit form i.e. right hand side (RHS) of the resulting system consists no derivative term, and left hand side (LHS) of every equation is only a single 1st order derivative term whose coefficient is $$1$$, but your system happens to be one that can't be transformed to that form:

Solve[{eq1, eq2}, {i1'[t], i2'[t]}]
(* {} *)


The output is {}, which indicates there's no solution.

If you don't want to see the warning, add Method -> {"EquationSimplification" -> "Residual"} / SolveDelayed -> True to NDSolve.

BTW, though the DAE solver works properly in this case, you may need to force NDSolve to use ODE solver in certain situations because ODE solver of NDSolve` is more robust compared to the DAE solver. (Andre has already shown you one possible approach in his comment. )

You may check this answer for more details.