0
$\begingroup$

I have piecewise function A which is defined as shown below. When I plot piecewise in Mathematica I could not able to see any points after x=3.5, but If I evaluate the A I am getting value. I am bit confused and curious why it is happening? Am I using the piecewise function properly?

z1 = 1;
z2 = 2;
z3 = 3;
L = 4;
a1 = -0.0664623 Cos[1.52648 x] + 0.0664621 Cosh[1.52648 x] + 
  0.0736429 Sin[1.52648 x] - 0.0736415 Sinh[1.52648 x] 
a2 = 0.0706263 Cos[1.52648 (-1 + x)] - 
  0.0012975 Cosh[1.52648 (-1 + x)] + 
  0.0696575 Sin[1.52648 (-1 + x)] - 0.0317435 Sinh[1.52648 (-1 + x)] 
a3 = 0.0727183 Cos[1.52648 (-2 + x)] - 
  0.0727174 Cosh[1.52648 (-2 + x)] - 0.413845 Sin[1.52648 (-2 + x)] + 
  0.267041 Sinh[1.52648 (-2 + x)] 
a4 = -0.410217 Cos[1.52648 (-3 + x)] + 
  0.410216 Cosh[1.52648 (-3 + x)] + 0.585447 Sin[1.52648 (-3 + x)] - 
  0.192384 Sinh[1.52648 (-3 + x)] 
A = Piecewise[{{a1, x <= z1}, {a2, z1 <= x <= z2}, {a3, 
    z2 <= x <= z3}, {a4, x >= z3}}]
Plot[A, {x, 0, L}]
$\endgroup$
  • 5
    $\begingroup$ Plot has a lot of hidden calculating going on. Part of this tries to decide what range to plot. If you change your code to Plot[A, {x, 0, L},PlotRange->All] it will show you everything out to 4. You can look up PlotRange to see how to give it even more precise instructions. $\endgroup$ – Bill Dec 2 '18 at 7:04
  • 1
    $\begingroup$ @acoustics in the last position put {a4, True} instead {a4, x >= z3} and take L=5 to check difference. $\endgroup$ – Alex Trounev Dec 2 '18 at 10:33
3
$\begingroup$

I have done some modifications on your code such that you can obtain your desired plot. If you want to have a different region in the plot you can change minX,maxX, minY and maxY values.

ClearAll["Global`*"];

z1 = 1;
z2 = 2;
z3 = 3;
L = 4;

a1[x_] := -0.0664623 Cos[1.52648 x] + 0.0664621 Cosh[1.52648 x] +    0.0736429 Sin[1.52648 x] - 0.0736415 Sinh[1.52648 x];
a2[x_] := 0.0706263 Cos[1.52648 (-1 + x)] - 0.0012975 Cosh[1.52648 (-1 + x)] + 0.0696575 Sin[1.52648 (-1 + x)] - 0.0317435 Sinh[1.52648 (-1 + x)];
a3[x_] := 0.0727183 Cos[1.52648 (-2 + x)] - 0.0727174 Cosh[1.52648 (-2 + x)] - 0.413845 Sin[1.52648 (-2 + x)] + 0.267041 Sinh[1.52648 (-2 + x)];
a4[x_] := -0.410217 Cos[1.52648 (-3 + x)] + 0.410216 Cosh[1.52648 (-3 + x)] + 0.585447 Sin[1.52648 (-3 + x)] - 0.192384 Sinh[1.52648 (-3 + x)];

A[x_] := Piecewise[{
{a1[x], x <= z1},
{a2[x], z1 <= x <= z2},
{a3[x], z2 <= x <= z3},
{a4[x], x >= z3}
}];


minX = 0;
maxX = L;

minY = -0.5;
maxY = A[L];

Plot[A[x], {x, 0, L}, PlotRange -> {{minX, maxX}, {minY, maxY}}]

When you run the code, you obtain

enter image description here

$\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.