数据可视化四:Matlab数据可视化(三)
2017-05-15 23:36
239 查看
数据可视化四:Matlab数据可视化(三)
目录:
1、绘制二维图形的常用函数。
2、绘制三维图形的常用函数。
3、绘制图形的辅助操作。
1、设
,在 x=0~2π区间取 101 点,绘制函数的曲线。
示例代码如下:
close all;
x=0 :pi / 50 : 2*pi;
y = (0.5 + 3 * sin(x)./ (1 + x.^2)).* cos(x);
plot(x,y);
运行结果如下:
图1.1 运行结果
2、已知
,完成下列操作:
(1) 在同一坐标系下用不同的颜色和线型绘制三条曲线。
示例代码如下:
close all;
x=linspace(0,2*pi,101);
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
plot(x,y1, 'g*');
hold on;
plot(x,y2,'ro');
hold on;
plot(x,y3,'b+');
运行结果:
图2.1 运行结果1
(2) 以子图形式绘制三条曲线。
示例代码如下:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
plot(x,y1);
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
plot(x,y2);
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
plot(x,y3);
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.2 运行结果2
(3) 分别用条形图、阶梯图、杆图和填充图绘制三条曲线。
①条形图代码示例:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
bar(x,y1);
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
bar(x,y2);
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
bar(x,y3);
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.3 运行结果3
②阶梯图代码示例:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
stairs(x,y1);
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
stairs(x,y2);
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
stairs(x,y3);
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.4 运行结果4
③杆图示例代码:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
stem(x,y1);
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
stem(x,y2);
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
stem(x,y3);
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.5 运行结果5
④填充图代码示例:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
fill(x,y1,'r');
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
fill(x,y2,'r');
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
fill(x,y3,'r');
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.6 运行结果6
3、已知:
在-5≤x≤5 区间绘制函数曲线。
答:示例代码如下:
close all;
x=-5:0.1:5;
y=(x+ sqrt(pi))/(exp(2)).*(x<=0)+1/2*log(x+sqrt(1+x.^2)).*(x>0);
plot(x,y);
运行结果:
图3.1 运行结果
4、绘制极坐标曲线ρ=asin(b+nθ),并分析参数 a、b、n 对曲线形状的影响。
答:示例代码如下:
close all;
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的值时,
运行结果:
图4.1 运行结果1
②当a、n的值不变,只改变b的值时,
运行结果:
图4.2 运行结果2
③当a、b的值不变,只改变n的值时,
图4.3 运行结果3
当b、n的值固定时,a决定图形的大小,当a为整数时,图形半径大小就是a;
当a、n的值固定时,b决定图形的旋转角度,图形的形状及大小不变;
当a、b的值固定时,n决定图形的扇叶数,当n为奇数时,扇叶数为n,当n为偶数时,扇叶数为2n。
5、绘制函数的曲面图和等高线。
其中 x 的 21 个值均匀分布[-5,5]范围,y 的 31 个值均匀分布在[0,10],要求使用
subplot(2,1,1)和 subplot(2,1,2)将产生的曲面图和等高线图画在同一个窗口上。
答:示例代码如下:
close all;
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);
colormap jet;
subplot(2,1,1);
surf(x,y,z);
title('曲面图');
subplot(2,1,2);
surfc(x,y,z);
title('等高线图');
运行结果:
图5.1 运行结果
6、绘制曲面图形:
答:示例代码如下:
close all;
s=linspace(0,pi/2,100);
t=linspace(0,3*pi/2,100);
[s,t]=meshgrid(s,t);
x=cos(s).*cos(t);
y=cos(s).*sin(t);
z=sin(s);
colormap jet;
surf(x,y,z);
运行结果:
图6.1 运行结果
目录:
1、绘制二维图形的常用函数。
2、绘制三维图形的常用函数。
3、绘制图形的辅助操作。
1、设
,在 x=0~2π区间取 101 点,绘制函数的曲线。
示例代码如下:
close all;
x=0 :pi / 50 : 2*pi;
y = (0.5 + 3 * sin(x)./ (1 + x.^2)).* cos(x);
plot(x,y);
运行结果如下:
图1.1 运行结果
2、已知
,完成下列操作:
(1) 在同一坐标系下用不同的颜色和线型绘制三条曲线。
示例代码如下:
close all;
x=linspace(0,2*pi,101);
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
plot(x,y1, 'g*');
hold on;
plot(x,y2,'ro');
hold on;
plot(x,y3,'b+');
运行结果:
图2.1 运行结果1
(2) 以子图形式绘制三条曲线。
示例代码如下:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
plot(x,y1);
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
plot(x,y2);
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
plot(x,y3);
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.2 运行结果2
(3) 分别用条形图、阶梯图、杆图和填充图绘制三条曲线。
①条形图代码示例:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
bar(x,y1);
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
bar(x,y2);
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
bar(x,y3);
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.3 运行结果3
②阶梯图代码示例:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
stairs(x,y1);
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
stairs(x,y2);
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
stairs(x,y3);
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.4 运行结果4
③杆图示例代码:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
stem(x,y1);
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
stem(x,y2);
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
stem(x,y3);
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.5 运行结果5
④填充图代码示例:
close all;
x=linspace(0,2*pi,101);
subplot(3,1,1);
y1=x.^2;
fill(x,y1,'r');
legend('y1=x.^2');
title('y1');
subplot(3,1,2);
y2=cos(2*x);
fill(x,y2,'r');
legend('y2=cos(2*x)');
title('y2');
subplot(3,1,3);
y3=y1.*y2;
fill(x,y3,'r');
legend('y3=y1.*y2');
title('y3');
运行结果:
图2.6 运行结果6
3、已知:
在-5≤x≤5 区间绘制函数曲线。
答:示例代码如下:
close all;
x=-5:0.1:5;
y=(x+ sqrt(pi))/(exp(2)).*(x<=0)+1/2*log(x+sqrt(1+x.^2)).*(x>0);
plot(x,y);
运行结果:
图3.1 运行结果
4、绘制极坐标曲线ρ=asin(b+nθ),并分析参数 a、b、n 对曲线形状的影响。
答:示例代码如下:
close all;
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的值时,
运行结果:
图4.1 运行结果1
②当a、n的值不变,只改变b的值时,
运行结果:
图4.2 运行结果2
③当a、b的值不变,只改变n的值时,
图4.3 运行结果3
当b、n的值固定时,a决定图形的大小,当a为整数时,图形半径大小就是a;
当a、n的值固定时,b决定图形的旋转角度,图形的形状及大小不变;
当a、b的值固定时,n决定图形的扇叶数,当n为奇数时,扇叶数为n,当n为偶数时,扇叶数为2n。
5、绘制函数的曲面图和等高线。
其中 x 的 21 个值均匀分布[-5,5]范围,y 的 31 个值均匀分布在[0,10],要求使用
subplot(2,1,1)和 subplot(2,1,2)将产生的曲面图和等高线图画在同一个窗口上。
答:示例代码如下:
close all;
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);
colormap jet;
subplot(2,1,1);
surf(x,y,z);
title('曲面图');
subplot(2,1,2);
surfc(x,y,z);
title('等高线图');
运行结果:
图5.1 运行结果
6、绘制曲面图形:
答:示例代码如下:
close all;
s=linspace(0,pi/2,100);
t=linspace(0,3*pi/2,100);
[s,t]=meshgrid(s,t);
x=cos(s).*cos(t);
y=cos(s).*sin(t);
z=sin(s);
colormap jet;
surf(x,y,z);
运行结果:
图6.1 运行结果
相关文章推荐
- Matlab数据可视化(2):基础篇 II
- Matlab数据可视化(4):一维数据绘图 II
- Matlab数据的可视化 -- 阶梯图
- Matlab数据的可视化 -- 图形格式的设置
- Matlab数据的可视化 -- 三维网格图形
- MATLAB-数据可视化笔记
- Matlab数据的可视化 -- 三维表面图
- Matlab数据的可视化 -- 条形图
- Matlab数据的可视化 -- 极坐标图及其与直角坐标图的转换
- Matlab数据的可视化 -- 柱形立体图
- Matlab数据可视化(5):二维数据可视化 I
- matlab的数据可视化
- MATLAB 数据分析二: 样本数据可视化--条形图、直方图、二/三维散点图
- Matlab数据的可视化 -- 饼图
- Matlab数据的可视化 -- 线性图函数plot
- Matlab数据可视化(3):一维数据绘图 I
- 机器学习----Matlab数据可视化总结(plot篇)
- Matlab学习笔记-数据和函数可视化
- Matlab数据的可视化 -- 平面多边形的着色
- Matlab数据的可视化 -- 简易表面图