1
$\begingroup$

I am unable to plot the solution to this differential equation in Mathematica representing the current in a RLC circuit with a sinusoidal input.

L*y''[t] == -R*y'[t] - C*y[t];
(*V\[Equal]Sin[t];*)
soln = DSolve[{L*y''[t] == -R*y'[t] - C*y[t], y[0] == 0, y'[0] == V}, 
     y[t], t][[1]] // Simplify;

With[{expr = y[t] /. soln}, 
 Manipulate[
  Plot[expr, {t, 0, 2*Pi}, 
   PlotRange -> {{0, 10}, {-5, 5}}], {{L, 1*^-3}, 0, 
   10*^-3}, {{R, 3*^3}, 1*^3, 10*^3}, {{C, 3*^5}, 0, 10*^5}, {{V, 5}, 
   0, 10}]]

I think my problem is either in defining my Differential equation or plotting. Any ideas?

$\endgroup$
1
  • 1
    $\begingroup$ When I can't get a Plot to work I try substituting Table. This Manipulate[ expr=y[t]/. DSolve[{L*y''[t]==-R*y'[t]-C*y[t], y[0]==0, y'[0]==V}, y[t], t][[1]]; Table[N[expr], {t,0,10}], {{L,1*^-3},0,10*^-3}, {{R,3*^3},1*^3,10*^3}, {{C,3*^5},0,10*^5}, {{V,5},0,10}] might let you know why your PlotRange->{{0,10},{-5,5}}] isn't showing you anything. $\endgroup$
    – Bill
    Commented Sep 29, 2018 at 4:02

1 Answer 1

2
$\begingroup$

Here is just the case when the exact solution is worse than numerical. Therefore, we solve numerically

 Manipulate[
 Plot[Evaluate[
   y[t] /. First[
     NDSolve[{L*y''[t] == -R*y'[t] - C0*y[t] + V*Sin[t], y[0] == 0, 
       y'[0] == V}, y, {t, 0, 2*Pi}]]], {t, 0, 2*Pi}], {{L, 1*^-3}, 
  10^-6, 10*^-3, Appearance -> "Labeled"}, {{R, 3*^3}, 1*^3, 10*^3, 
  Appearance -> "Labeled"}, {{C0, 3*^5}, 0, 10*^5, 
  Appearance -> "Labeled"}, {{V, 5}, 0, 10, Appearance -> "Labeled"}]

fig1

$\endgroup$
2
  • 2
    $\begingroup$ Recommend that you add Appearance -> "Labeled" to each control. $\endgroup$
    – Bob Hanlon
    Commented Sep 29, 2018 at 15:28
  • $\begingroup$ @Bob Hanlon Thank you, I added the code and changed the picture. $\endgroup$ Commented Sep 30, 2018 at 4:17

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.