1
$\begingroup$

I tried both Dsolve and NDsolve for the following differential equation, it failed: It contains piecewise function

   Clear["Global`*"]
i[\[Alpha]_, t_, vs_, tmax_] := 
 Piecewise[{{0, t < 0}, {\[Alpha] t , 0 < t < (vs/\[Alpha])}, {vs, 
    tmax > t > (vs/\[Alpha])}}]
Clear[\[Alpha], vs, vsmin, vsmax, \[Alpha]max, \[Alpha]min, \[Beta], 
  g, tmax, c, cres, tr];

Dsolve[{(vs - vc[t]) g == 
    i[\[Alpha], t, vs, tmax] + (1 + g*cres)*c*vc'[t], vc[0] == vs} vc[
   t], t]
Clear[\[Alpha], vs, vsmin, vsmax, \[Alpha]max, \[Alpha]min, \[Beta], 
  g, tmax, c, cres, tr];
tr = 30*10^-12
vs = 1;
\[Alpha] = vs/tr;
g = 1*10^3;
c = 6*10^-9;
\[Beta] = 5;
cres = 0.4;
tmax = \[Beta]*tr;
Plot[i[\[Alpha], t, vs, tamx], {t, 0, tmax}]
NDSolve[{(vs - vc[t]) g == 
   i[\[Alpha], t, vs, tmax] + (1 + g*cres)*c*vc'[t], 
  vc[0] == vs}, vc, {t, 0, tmax}]
Plot[Evaluate[vc[t], {t, 0, tmax}], PlotRange -> All]

It keeps giving me the same input but reshaped

Would you please help?

$\endgroup$
1
  • 2
    $\begingroup$ You should put the "Clear" at the beginning followed by definitions of constants. Then correct spelling error in Dsolve. Further, the syntax of "Piecewise" is wrong, you can not write: {t, 0, tmax} $\endgroup$ Commented Nov 2, 2020 at 12:22

1 Answer 1

2
$\begingroup$

Try this

Clear["Global`*"]
Clear[\[Alpha], vs, vsmin, vsmax, \[Alpha]max, \[Alpha]min, \[Beta], g, tmax, c, cres, tr];
i[\[Alpha]_, t_, vs_, tmax_] := Piecewise[{{0, t < 0}, {\[Alpha] t, 0 < t < (vs/\[Alpha])}, {vs, tmax > t > (vs/\[Alpha])}}]
tr = 30*10^-12;
vs = 1;
\[Alpha] = vs/tr;
g = 1*10^3;
c = 6*10^-9;
\[Beta] = 5;
cres = 0.4;
tmax = \[Beta]*tr;
Plot[i[\[Alpha], t, vs, tmax], {t, 0, tmax}, PlotRange -> All]
vct = vc[t] /. DSolve[{(vs - vc[t]) g == i[\[Alpha], t, vs, tmax] + (1 + g*cres)*c*vc'[t], vc[0] == vs}, vc[t], t]
Plot[vct, {t, 0, tmax}, PlotStyle -> {Thick, Blue}, PlotRange -> All]
$\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.