4
$\begingroup$

I have a simple electrical circuit of an ideal transformer:

circuit

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] == 0;
ic2 = i2[0] == 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:

solution

which corresponds to my LTSpice solution:

LTSpice_current LTSpice_voltage

Now my problem is that I get the following warning:

NDSolveValue::ntdvdae: Cannot solve to find an explicit formula for the derivatives. NDSolve will try solving the system as differential-algebraic equations.

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?

$\endgroup$
6
  • $\begingroup$ If you try to bring {eq1,eq2} in an explicit form you'll recognize some problems. That's the error message MMA shows! $\endgroup$ Commented Nov 14, 2018 at 11:09
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Nov 14, 2018 at 11:36
  • $\begingroup$ 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. $\endgroup$
    – andre314
    Commented Nov 14, 2018 at 11:59
  • $\begingroup$ @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? $\endgroup$ Commented Nov 14, 2018 at 12:27
  • $\begingroup$ @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. $\endgroup$ Commented Nov 14, 2018 at 12:32

1 Answer 1

4
$\begingroup$

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][[1]]

Plot[{analyticsol@t, sol[t]}, {t, 0, time}, PlotStyle -> {Automatic, {Red, Dashed}}, 
 PlotLegends -> {"Analytic Solution", "Numeric Solution"}]

Mathematica graphics

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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