3
$\begingroup$

I have a differential equation that I need to solve it in mathematica. The equation looks like this:

R * (dV/dt) + (1/C) * V + P1 = P2 

Where R,C,P1,P2 are constants I tried to write it as:

DSolve[{Vi'[t] + Vi[t]*(1/c) + p1 == p2}, Vi[t], t]

Is it good like this? Or should I write it in another way? I ask this because if I transform the equation in:

dV/dt + V/R*C = (P2 - P1) / R 

it gives me another solution in mahematica

$\endgroup$

1 Answer 1

2
$\begingroup$

Do not use UpperCase single letters in M. If you must, add 0 to the letter. Write the ode on its own first to make sure it is OK. Clear all variables first. Notice that C is build-in constant. So is K and E and D and may be more. That is why it is not good idea to use SingleLetterUpperCase for variables.

ClearAll[v, t, C0, p1, p2, R0];
ode = R0 * v'[t] + (1/C0)*v[t] + p1 == p2

Mathematica graphics

Now solve it

sol=v[t]/.First@DSolve[ode,v[t],t]

Mathematica graphics

C[1] above is the constant of integration.

If you have IC, then write these also on separate line

ClearAll[v,t,C0,p1,p2,R0];

ode = R0* v'[t] +(1/C0)*v[t]+p1==p2
ic  = v[0]==0;
sol = DSolve[{ode,ic},v[t],t]

Mathematica graphics

do not get into the habit (which many seems to have) of putting everything in one command, like this

sol=DSolve[{R0* v'[t] +(1/C0)*v[t]+p1==p2,v[0]==0},v[t],t]

It makes the code harder to read and modify. Also if you had made an error in the definition of the ODE or the IC, then it would be easier to see the error if those definitions were in separate command.

$\endgroup$
1
  • $\begingroup$ Thank you very much sir! $\endgroup$ Nov 18, 2017 at 12:23

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.