3
$\begingroup$

I have a system of differential equations that can be solved with DSolve. However, the coefficients are very long there are like terms which can be combined. I used //FullSimplify in my code but the output of DSolve is still too complicated. Is there a way for Mathematica to turn all the coefficients into decimals and then combine the like terms?

Remove["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] // FullSimplify

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]}]
$\endgroup$
3
  • $\begingroup$ s // N // Simplify or Simplify@N@s or Simplify[N[s]]. $\endgroup$
    – march
    Commented Aug 25, 2015 at 19:50
  • $\begingroup$ I tried added these to my code but then there are some errors. I don't think i'm using these commands right. What does s and N stand for or do i just directly copy and paste them into my code? $\endgroup$
    – jerry
    Commented Aug 26, 2015 at 14:01
  • $\begingroup$ s is the name you gave to the output of DSolve. You can look up N in the MMA help files (which you should be in the habit of doing). So s // N // Simplify is a command you would add to the code on the line after the definition of s (and you should remove the FullSimplify). $\endgroup$
    – march
    Commented Aug 26, 2015 at 15:10

1 Answer 1

4
$\begingroup$
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] // FullSimplify;

(s[[1]] // Expand) /. n_?NumberQ :> N[n]

(*  {V1[t] -> 399601. - 0.000333138 E^(-408.622 t) - 399600. E^(-8.39765*10^-7 t),  
     V2[t] -> 399600. - 0.000333138 E^(-408.622 t) - 399600. E^(-8.39765*10^-7 t),   
     V3[t] -> 399600. + 0.000821224 E^(-408.622 t) - 399600. E^(-8.39765*10^-7 t)}
*)

EDIT: Note that the PatternTest ?NumberQ is used rather than ?NumericQ to avoid converting the constant E to its numerical value.

$\endgroup$
3
  • $\begingroup$ wow the addition of that line works wonderfully. Can you explain what is actually going on in it though? I've never seen most of those commands before. $\endgroup$
    – jerry
    Commented Aug 26, 2015 at 14:05
  • $\begingroup$ @jerry - see EDIT. In general, highlight unknown commands or operators and press F1 for help (documentation). $\endgroup$
    – Bob Hanlon
    Commented Aug 26, 2015 at 14:21
  • $\begingroup$ ahh okok ill play around with that then $\endgroup$
    – jerry
    Commented Aug 26, 2015 at 14:47

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.