数值计算画图练习记录
程序员文章站
2023-12-29 17:40:58
...
画图
代码
a=4;b=2;
t=0:2*pi/100:2*pi;
x=a*cos(t);y=b*sin(t);
plot(x,y,'r','Marker','diamond');
axis([-4,4,-3,3]);
xlabel('x');ylabel('y');
%第二题
theta=0:pi*2/100:2*pi;
p=1-cos(theta);
axis square;
handle=polar(theta,p,'r');
set(handle,'LineWidth',3);
%第三题
A=[170,120,180,200,190,220];
B=[120,100,110,180,170,180];
C=[70,50,80,100,95,120];
bar([1:1:6],[A' B' C'],'stacked');
legend('A','B','C','location','northwest');
%第四题
for x=0:1:120
if x<60
y(x+1)=sin(x/10-6);
elseif (x>=60)&&(x<=90)
y(x+1)=x/10-6;
else
y(x+1)=-x/10+12;
end
end
x=-6:0.1:6;
plot(x,y,'k','Color','r');
xlabel('x');ylabel('y');
推荐阅读