转载地址:http://bbs.ednchina.com/BLOG_ARTICLE_2103818.HTM
(1)y=1/x:
n=0:10:1000;y=1./n;
plot(n,y)
grid on
(2)y=x*x:
n=-1000:10:1000;
y=n.*n;
plot(n,y)
grid on
(3)
x=0:1:1000;
y=0.065*x+(102*x)+(7154*100./(x+100));
plot(x,y)
grid on
(4)
syms x
y=x^2;
ezplot(y,[0,100])
grid on
(5)分段函数
x=-3:0.01:3;
y1=zeros(size(x));
y2=zeros(size(x));
y3=zeros(size(x));
N=length(x);
for k=1:N
if x(k)<-1&x(k)>=-3;
y1(k)=(-x(k).^2-4*x(k)-3)/2;
elseif x(k)>=-1&x(k)<1 ;
y2(k)=-x(k).^2+1;
else x(k)<=3&x(k)>=1 ;
y3(k)=(-x(k).^2+4*x(k)-3)/2;
end
end
y=y1+y2+y3;
plot(x,y)
(6) 保留轨迹法,分段函数
syms x
x1=0:1:10;
x2=10:1:20;
f1=x*10;
f2=x^2;
hold on
plot(x1,subs(f1,x,x1),'r','LineWidth',2.5)
plot(x2,subs(f2,x,x2),'r','LineWidth',2.5)
legend(char(f1),char(f2),'Location','NorthEast')
grid on
xlabel('x')
hold off
(7)曲线
clear
syms x
x1=0:10:433;
x2=434:10:14300;
n1=0:341:1023;
n2=0:1:1023;
m1=530;
m2=391;
m3=254;
m4=117;
hold on
N=length(n1);
for k=1:N
f1=x*0.75 + (n1(k)*14 - 7161)*x/15000;
plot(x1,subs(f1,x,x1),'r','LineWidth',1)
f2=x*(827-m1)/13866+m1-434*(827-m1)/13866;
plot(x2,subs(f2,x,x2),'r','LineWidth',1)
f2=x*(827-m2)/13866+m2-434*(827-m2)/13866;
plot(x2,subs(f2,x,x2),'r','LineWidth',1)
f2=x*(827-m3)/13866+m3-434*(827-m3)/13866;
plot(x2,subs(f2,x,x2),'r','LineWidth',1)
f2=x*(827-m4)/13866+m4-434*(827-m4)/13866;
plot(x2,subs(f2,x,x2),'r','LineWidth',1)
end
hold off