Both Dsolve and NDsolve for a differential equation failed

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

• 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} Commented Nov 2, 2020 at 12:22

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]