目录
一、
二、
三、
四、
五、
如对你有帮助记得点赞哦
一、
绘制函数曲线。设,把x=0~2π区间分为101点,绘制函数的曲线。
---------------------------------------示例代码---------------------------------------------
x=linspace(0,2*pi,101);
y=(0.5+3*sin(x)./(1+x.^2)).*cos(x);
plot(x,y)
---------------------------------------运行结果---------------------------------------------
(2)已知,在-5≤x≤5区间绘制函数曲线。
---------------------------------------示例代码---------------------------------------------
x=-5:0.01:5;
y=[]; %起始设y为空向量
for x0=x
if x0<=0 %不能写成x0=<0
y=[y,(x0+sqrt(pi))/exp(2)]; %将x对应的函数值放到y中
else
y=[y,0.5*log(x0+sqrt(1+x0^2))];
end
end
plot(x,y)
---------------------------------------运行结果---------------------------------------------
(3)绘制极坐标曲线p=10sin(1+50)。
---------------------------------------示例代码---------------------------------------------
theta=0:pi/100:2*pi;
rho=10*sin(1+5*theta);
polarplot(theta,rho);
---------------------------------------运行结果---------------------------------------------
二、
已知y1=x2,y2=cos(2x),y3=y1*y2,完成下列操作。
(1)在同一坐标系下用不同的颜色和线型绘制3条曲线。
---------------------------------------示例代码---------------------------------------------
x=-pi:pi/100:pi;
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
plot(x,y1,'b-',x,y2,'r',x,y3,'k--');
---------------------------------------运行结果---------------------------------------------
(2)以子图形式绘制3条曲线。
---------------------------------------示例代码---------------------------------------------
x=linspace(-pi,pi,100);
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
subplot(3,1,1)
plot(x,y1,'r*')
subplot(3,1,2)
plot(x,y2,'g.')
subplot(3,1,3)
plot(x,y3,'b--')
---------------------------------------运行结果---------------------------------------------
(3)分别用条形图、阶梯图、杆图和填充图绘制3条曲线。
---------------------------------------示例代码---------------------------------------------
x=0:pi/100:2*pi;
y1=x.*x;y2=cos(2*x);
y3=y1.*y2;subplot(4,3,1);
bar(x,y1,'r');
subplot(4,3,2);
bar(x,y2,'k');
subplot(4,3,3);
bar(x,y3,'b');
subplot(4,3,4);
stairs(x,y1,'r');
subplot(4,3,5);
stairs(x,y2,'k');
subplot(4,3,6);
stairs(x,y3,'b');
subplot(4,3,7);
stem(x,y1,'r');
subplot(4,3,8);
stem(x,y2,'k');
subplot(4,3,9);
stem(x,y3,'b');
subplot(4,3,10);
fill(x,y1,'r');
subplot(4,3,11);
fill(x,y2,'k');
subplot(4,3,12);
fill(x,y3,'b');
---------------------------------------运行结果---------------------------------------------
三、
绘制三维曲线。
---------------------------------------示例代码---------------------------------------------
t=0:pi/100:2*pi;
x=(2+cos(t/2)).*cos(t);
y=(2+cos(t/2)).*sin(t);
z=sin(t/2);
plot3(x,y,z)
---------------------------------------运行结果---------------------------------------------
四、
绘制函数的曲面图和等高线。
其中x的21个值均匀分布在[-5,5]范围,y的31个值均匀分布在[0,10],要求使用subplot(2,1,1)和subplot(2,1,2)将产生的曲面图和等高线图画在同一个窗口上。
---------------------------------------示例代码---------------------------------------------
x=linspace(-5,5,21);
y=linspace(0,10,31);
[x,y]=meshgrid(x,y);
z=cos(x).*cos(y).*exp(-sqrt(x.^2+y.^2)/4);
subplot(2,1,1);
surf(x,y,z);
title('曲面图');
subplot(2,1,2);
surfc(x,y,z);
%contour3(x,y,z,50);%其中50为高度的等级数,越大越密
title('等高线图')
---------------------------------------运行结果---------------------------------------------
五、
绘制曲面图形,并进行插值着色处理。
---------------------------------------示例代码---------------------------------------------
ezsurf('cos(s)*cos(t)','cos(s)*sin(t)','sin(s)',[0,0.5*pi,0,1.5*pi]);
---------------------------------------运行结果---------------------------------------------
文章来源:https://www.toymoban.com/news/detail-439501.html
如有侵权,请尽快与我联系!文章来源地址https://www.toymoban.com/news/detail-439501.html
到了这里,关于7、MATLAB程序设计与应用刘卫国(第三版)课后实验七:绘图操作的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!