求教大神,怎么用MATLAB画线性函数
1个回答

附带程序:

x=-0.3:0.01:1.2;

>> v1=1.*(x>=0&x

.1&x

.3);

>> plot(x,v1)

grid on

gtext('v1')

>> hold on

>> v2=5*(x-0.1).*(x>=0.1&x<0.3)+[1-5*(x-0.3)].*(x>=0.3&x<0.5)+0.*(x<0.1&x>0.5);

>> plot(x,v2)

plot(x,v2,'r:')

gtext('v2')

>> hold on

v3=5*(x-0.3).*(x>=0.3&x<0.5)+[1-5*(x-0.5)].*(x>=0.5&x<0.7)+0.*(x<0.3&x>0.7);

plot(x,v3,'g')

gtext('v3')

hold on

v4=5*(x-0.7).*(x>=0.7&x<0.9)+[1-5*(x-0.7)].*(x>=0.7&x<0.9)+0.*(x<0.7&x>0.9);

>> plot(x,v4,'b')

gtext('v4')

v5=5*(x-0.7).*(x>=0.7&x<0.9)+1.*(x>=0.9)+0.*(x<0.7&x>0.9);

hold on

plot(x,v5,'y')

gtext('v5')

另修改:axis([-0.3,1,0,1.2])

修改 v4=5*(x-0.5).*(x>=0.5&x<0.7)+[1-5*(x-0.7)].*(x>=0.7&x<0.9)+0.*(x<0.7&x>0.9);

plot(x,v4,'black')