# How to draw the image of piecewise function in MATLAB

Time：2020-10-12

Usually, if you want to use matlab to draw the image of piecewise function, it is very troublesome to draw it in sections, and you need hold on. Now I will teach you a method to simplify the piecewise function and let you know the charm of this method at once!

Software name:
Mathematical software MATLAB r2019b for Linux 64 bit official Chinese Version (with installation method and image)
Software size:
126MB
Update time:
Software name:
Matlab r2018b win64 bit Chinese Special Edition (with license file + installation key + activation method)
Software size:
12.0GB
Update time:

The steps are as follows:

The first step, for example, is to draw such a piecewise function image“

-4<x<4;y=3*x;

4<=x<12;y=20;

12 < = x < 18; y = – 5x + 2; “, as shown in the figure below: The second step is to express it in MATLAB,y=(3*x).*(x>=-4&x<4) + 20*(x>=4&x<12)+(-5*x+2).*(x>12&x<=18)As shown in the figure below: Step 3: enter x = – 4:0.1:18xIs also a piecewise functionxAs shown in the following figure: Step 4 m script input

x=-4:0.1:18

y=(3*x).*(x>=-4&x<4) + 20*(x>=4&x<12)+(-5*x+2).*(x>12&x<=18)

plot(x,y)

”Code, as shown in the following figure: The fifth step is to run the script, you can see that the segmented function image has been drawn, mainly using MATLAB to express the segmented function, and then using theplotJust draw a picture, as shown in the following figure: 