0
|
13309 Views
|
4 Replies
|
2 Total Likes
View groups...
Share

# Piecewise function

Posted 9 years ago
 Dear friends I need to define and plot a 6-piecewise function but the software only accept 3 and when i try to add more, the font color changes to red and the program does not execute. Can anyone help me? All the best
4 Replies
Sort By:
Posted 9 years ago
 Hi Philip,I see the same thing. It can be eliminated by increasing the number of points plotted. But I do think it would be better if Plot knew to plot to the endpoints of segments. Plot[{Piecewise[{{0.6 - 0.3692*(x + 3) - 0.0308*(x + 3)^3, -3 < x <= -2}, {0.2 - 0.46154*(x + 2) - 0.0923*(x + 2)^2 + 0.95385*(x + 2)^3, -2 < x <= -1}, {0.6 + 2.2154*(x + 1) + 2.7692*(x + 1)^2 - 2.5846*(x + 1)^3, -1 < x <= 0}, {3 - 4.9846*x^2 + 2.58462*x^3, 0 < x <= 1}, {0.6 - 2.21538*(x - 1) + 2.76923*(x - 1)^2 - 0.95384*(x - 1)^3, 1 < x <= 2}, {0.2 + 0.46154*(x - 2) - 0.0923*(x - 2)^2 + 0.0308*(x - 2)^3, 2 < x <= 3}}], 3 - 3.20667*x^2 + 0.866667*x^4 - 0.06*x^6}, {x, -3, 3}, PlotPoints -> 1000] 
Posted 9 years ago
 Thanks to Blinder and DavidVia your instructions, I plotted the 6-piecewise function (Blue) and a 6th order polynomial function (Pink) at the same time. but the piecewise function has a discontinuity at x=-2 and a bit right while it shouldn't be like that since it is a 3rd order polynomial!!! Any reason? Enclosed find the code. Any comment will be welcome. Attachments:
Posted 9 years ago
 The region specifications are a list of lists. You forgot the outer brackets.Best, David (* this *) Piecewise[{0, x < 1}, {1, x < 2}, {3, x < 3}, {4, x < 4}, {5, True}] (* should be this *) Piecewise[{{0, x < 1}, {1, x < 2}, {3, x < 3}, {4, x < 4}, {5, True}}] 
Posted 9 years ago
 Try defining a 2-part piecewise function, each piece itself being a 3-part piecewise function. Or, alternatively, 3 then 2.