I have a Piecewise function that must be non-negative. I want to replace negative part of this function with zero. my function has two summit and two valley. I want to remove this valley because in my piecewise function negative value is not reasonable. I tried for define a new piecewise -F[t]- for replace this valley with zero!!! but my piecwise cant Diagnosis the positiveness of my first summit. what's my mistake? please help me for find my mistake.I used Heaviside and piecewise but they didn't work for my FN[t]!!! I can use Piecewise, Piecewise and heaviside together but any of them dont work for my FN[t] and all of them remove my first positive summit. you can see picture of my resultant Positive function or copy past my code in your mathematica and see the result.
ClearAll[sol, m, e, K, F, FN, d, yGroundContact, yBodyContact,
Ballradius, Cmax, yCM, eq1, InitialConditions, A]
m = 32.6767;
g=9.81;
(*Contact Parameters*)
K = 100000000;
e = 1.5;
Cmax = 10000;
d = 0.000001;
Ballradius = 0.1;
yGroundContact[t_] := 0;
yBodyContact[t_] := yCM[t] - Ballradius;
STEP[t_] :=
Piecewise[{{1,
yBodyContact[t] < (yGroundContact[t] - d)}, {1/
2*(1 - Sin[Pi/d*(yBodyContact[t] - yGroundContact[t]) + Pi/2]),
yGroundContact[t] >=
yBodyContact[t] > (yGroundContact[t] - d)}, {0,
yBodyContact[t] > (yGroundContact[t])}}];
FN[t_] :=
Piecewise[{{0,
yBodyContact[t] >
yGroundContact[t]}, {K*
Abs[(yGroundContact[t] - yBodyContact[t])]^e -
Cmax*(yBodyContact'[t] - yGroundContact'[t])*STEP[t],
yBodyContact[t] <= yGroundContact[t]}}];
F[t_] := Piecewise[{{FN[t], FN[t] >= 0}, {0, FN[t] < 0}}];
A[t_] := Piecewise[{{10000, FN[t] >= 0}, {0, FN[t] < 0}}];
eq1 = m*yCM''[t] + m*g == +FN[t];
InitialConditions = {yCM[0] == 0.4, yCM'[0] == 0};
sol = NDSolve[{eq1, InitialConditions}, yCM, {t, 0, 10},
MaxStepSize -> 0.0001];
Plot[{FN[t] /. sol, A[t] /. sol}, {t, 0, 0.5}, PlotRange -> Full,
AspectRatio -> 1/4, ImageSize -> 1400,
PlotStyle -> {{Red, Thickness[0.002]}, {Blue, Thickness[0.002],
Dashed}, {Orange, Thick, Dotted}}]
Plot[{F[t] /. sol, A[t] /. sol}, {t, 0, 0.5}, PlotRange -> Full,
AspectRatio -> 1/4, ImageSize -> 1400,
PlotStyle -> {{Red, Thickness[0.002]}, {Blue, Thickness[0.002],
Dashed}, {Orange, Thick, Dotted}}]
Clip[]
is intended for... $\endgroup$g
andA
. Please double check it. $\endgroup$