2
$\begingroup$
  1. What do I get the Syntax::sntxi: Incomplete expression; more input is needed . error when I try to use the math palette for derivatives?

  2. What does the dot in 10. Farad Micro Volt mean? Multiplication?

  3. Why is my C1 changed to C[1]? What does that mean? Basically I wanted to use C for capacitance but the letter C was protected.

  4. How come my unit convert isn't working? What's the easiest way to get my final result in units? wolframalpha.com often will figure out what units you want but only allows you enter one line so I'm trying to learn Mathematica

    R := 500 Ohm 
    C1 := 0.5 Micro Farad 
    V := 20 Volt
    DSolve[R*q1'[t] + 1/C1*q1[t] == V, q1[t], t]
    (* {{q1[t] -> 10. Farad Micro Volt + E^(-((0.004 t)/(Farad Micro Ohm))) C[1]}} *)
    
    TraditionalForm[R*q1'[t] + 1/C1*q1[t] == V]
    (* (2. q1(t))/(Farad Micro)+500 Ohm q1^′(t)==20 Volt *)
    
    R := 500 Ohm 
    C1 := 0.5 Micro Farad 
    V := 20 Volt
    DSolve[R*(\[DifferentialD]/\[DifferentialD]t)q1[t] + 1/C1*q1[t] == V, q1[t], t]
    
    (* During evaluation of In[89]:= Syntax::sntxi: Incomplete expression; more input is needed . *)
    
    UnitConvert[10.` Farad Micro Volt + E^(-((0.004` t)/(Farad Micro Ohm))) C[1], Coulomb]
    (* UnitConvert[10. Farad Micro Volt + E^(-((0.004 t)/(Farad Micro Ohm))) C[1], Coulomb] *)
    
$\endgroup$
  • 1
    $\begingroup$ 2) 10. is an inexact number. A real. 3) Just coincidence. C[1] is a default unknown variable. see the docs for the option GeneratedParameters. $\endgroup$ – Mike Honeychurch Jan 10 '16 at 11:49
4
$\begingroup$

I don't think units are going to work with this calculation.

I couldn't find any way to give t a dimension of time that would be accepted by DSolve, although the documentation seems to suggest that it isn't necessary. This leads us to the following:

r = Quantity[500, "Ohms"];
c = Quantity[0.5, "Microfarads"];
v = Quantity[20 , "Volts"];
DSolve[{
   r*Quantity[q1'[t], "Coulombs"/"Seconds"] +
    1/c*Quantity[q1[t], "Coulombs"] == v
  }, q1[t], t
 ]

failed DSolve output with Solve::units messages

Clearly, DSolve failed. It makes no difference if you use "Amperes" instead of "Coulombs"/"Seconds". I tried a number of other potentially acceptable ways of stating the input, but they seemed to confuse DSolve even more and none of them produced any better result than this.

NDSolve doesn't produce an output with units and won't accept q1[0] == Quantity[0, "Coulombs"] as an initial condition. But note that it did not complain about units being present in the input and the time-scaling of the result is correct for the unit of microfarads, so clearly it did something correctly with units:

r = Quantity[500, "Ohms"];
c = Quantity[0.5, "Microfarads"];
v = Quantity[20 , "Volts"];
sol = NDSolveValue[{
   r*Quantity[q1'[t], "Coulombs"/"Seconds"] +
    1/c*Quantity[q1[t], "Coulombs"] == v,
   q1[0] == 0
  }, q1[t], {t, 0, 1*^-3}
 ];
Plot[q1[t] /. sol, {t, 0, 1*^-3}]

Plot of NDSolve output for capacitor charging

You could use ParametricNDSolve(Value) to parameterize the initial charge.

The most successful approach is just DSolve without any attempt to use units:

r = 500;
c = 0.5*^-6;
v = 20;
sol = DSolve[{r*q1'[t] + 1/c*q1[t] == v, q1[0] == x}, q1[t], t]
(* -> {{q1[t] -> 0.00001 E^(-4000. t) (-1. + 1. E^(4000. t) + 100000. x)}} *)

Plot[q1[t] /. sol /. x -> 0, {t, 0, 1*^-3}]

Plot of DSolve output without units for capacitor charging

Units have not been part of Mathematica for very long and this frustrating experience does not seem to be unusual for people attempting to work with them. To avoid such things, my suggestion would be to do the value and units calculations separately.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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