【matlab】实验四:数据可视化+matlab绘图

题目一

1.设y=cos(x)(0.5+3sin(x)/(1+x^2)),把x=0~2*pi间分为101点,绘制图像
在这里插入图片描述

clear;clc;
x=0:2*pi/100:3*pi;
y=cos(x)*(0.5+3*sin(x)/(1+x.^2));	%注意这里是.^
figure;
plot(x,y,'-')

运行结果:
在这里插入图片描述

题目二

2.已知y1=x^2,y2=cos(2x),y3=y1*y2,完成下列操作
(1)在同一坐标系中的不同颜色和线型绘制三条曲线
(2)以子图像绘制三条曲线
(3)分别用条形图,阶梯图,杆图和填充图绘制三条曲线

clear;clc;
x=0:2*pi/100:2*pi;
y1=x.^2;	%注意是.^
y2=cos(2*x);
y3=y1.*y2;
%%在同一坐标系下用不同的颜色和线型绘制三条曲线。
figure
plot(x,y1,'-b',x,y2,':r',x,y3,'--k')
text(5,32,'y1=x^2','Color','b');
text(5.5,21,'y2=cos(2*x)','Color','k');
text(5.9,1,'y3=y1*y2','Color','r');
%%以子图形式绘制三条曲线。
subplot(2,2,1),plot(x,y1)
title("y1=x^2")
subplot(2,2,2),plot(x,y2)
title("y2=cos(2*x)")
subplot(2,2,3),plot(x,y3)
title("y3=y1*y2")
%%
%分别用条形图、阶梯图、杆图和填充图绘制三条曲线
%条形图
subplot(4,3,1),bar(x,y1);title("y1=x^2")
subplot(4,3,2),bar(x,y2);title("y2=cos(2*x)")
subplot(4,3,3),bar(x,y3);title("y3=y1*y2")
%阶梯图
subplot(4,3,4),stairs(x,y1,'k');title("y1=x^2")
subplot(4,3,5),stairs(x,y2,'b');title("y2=cos(2*x)")
subplot(4,3,6),stairs(x,y3,'c');title("y3=y1*y2")
%杆图
subplot(4,3,7),fill(x,y1,'k');title("y1=x^2")
subplot(4,3,8),fill(x,y2,'b');title("y2=cos(2*x)")
subplot(4,3,9),fill(x,y3,'c');title("y3=y1*y2")
%填充图
subplot(4,3,10),stem(x,y1,'k');title("y1=x^2")
subplot(4,3,11),stem(x,y2,'b');title("y2=cos(2*x)")
subplot(4,3,12),stem(x,y3,'c');title("y3=y1*y2")

运行结果:
(1)
在这里插入图片描述
(2)在这里插入图片描述
(3)
在这里插入图片描述

题目三

3.已知y=(x+sqrt(pi))/e^2,x<=0&x>=-5
(1/2) * log(x+sqrt(1+x^2)),x>0&x<=5
在-5≤x<5区间绘制函数曲线
在这里插入图片描述

x=-5:0.01:5;
y=(x+sqrt(pi))/exp(2).*(x<=0&x>=-5)+0.5*log(x+sqrt(1+x.^2)).*(x>0&x<=5);
plot(x,y)

运行结果:
在这里插入图片描述

题目四

4.绘制函数的曲线图和等高线。
z=cosx* cosy * e^(-(sqrt(x ^2+ y^2)/4))
其中x的21个值均匀分布[-5,5]范围, y的31个值均匀分布在[0, 10],要求使用subplot(2,1,1)和subplot(2,1,2)将产生的曲面图和等高线图画在同一个窗口上。
在这里插入图片描述

clc;clear;
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);
title("等高线图")

运行结果:
在这里插入图片描述

题目五

5.绘制极坐标曲线ρ=a*sin(b+nθ),并分析参数a、b、n对曲线形状的影响。
在这里插入图片描述

close all;clc;clear;
%在一个figure里展现4个图片,固定变量进行比较
x=-2*pi:pi/100:2*pi;
%左上
subplot(2,2,1);
a=input('input a:');
b=input('input b:');
n=input('input n:');
y=a*sin(b+n*x);
polar(x,y);
title(sprintf('a=%d,b=%d,n=%d',a,b,n));
%右上
subplot(2,2,2);
a=input('input a:');
b=input('input b:');
n=input('input n:');
y=a*sin(b+n*x);
polar(x,y);
title(sprintf('a=%d,b=%d,n=%d',a,b,n));
%左下
subplot(2,2,3);
a=input('input a:');
b=input('input b:');
n=input('input n:');
y=a*sin(b+n*x);
polar(x,y);
title(sprintf('a=%d,b=%d,n=%d',a,b,n));
%右下
subplot(2,2,4);
a=input('input a:');
b=input('input b:');
n=input('input n:');
y=a*sin(b+n*x);
polar(x,y);
title(sprintf('a=%d,b=%d,n=%d',a,b,n));

当b、n的值固定时在这里插入图片描述

当a、n的值固定时在这里插入图片描述

当a、b的值固定时在这里插入图片描述

综上:
当b、n的值固定时,a决定图形的大小,当a为整数时,图形半径大小就是a;
当a、n的值固定时,b决定图形的旋转角度,图形的形状及大小不变;
当a、b的值固定时,n决定图形的扇叶数,当n为奇数时,扇叶数为n,当n为偶数时,扇叶数为2n。

  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值