MATLAB编程练习(含答案很好的)(5)
end;
end; s
031continue 语句的使用: for i=100:120; if rem(i,7)~=0; continue; end; i end
032
x=input ('输入X的值 x=') if x<1
y=x^2; elseif x>1&x<2 y=x^2-1; else
y=x^2-2*x+1; end y
033求阶乘的累加和 sum=0; temp=1; for n=1:10;
temp=temp*n; sum=sum+temp; end sum
034对角线元素之和
sum=0;
a=[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16]; for i=1:4;
sum=sum+a(i,i); end sum
21
035用拟合点绘图 A=[12 15.3 16 18 25]; B=[50 80 118 125 150.8]; plot(A,B)
036绘制正玄曲线: x=0:0.05:4*pi; y=sin(x); plot(x,y)
037绘制向量
x=[1 2 3 4 5 6;7 8 9 10 11 12;13 14 15 16 17 18] plot(x)
x=[0 0.2 0.5 0.7 0.6 0.7 1.2 1.5 1.6 1.9 2.3] plot(x)
x=0:0.2:2*pi y=sin(x)
plot(x,y,'m:p')
038在正弦函数上加标注: t=0:0.05:2*pi; plot(t,sin(t))
set(gca,'xtick',[0 1.4 3.14 56.28]) xlabel('t(deg)')
ylabel('magnitude(v)')
title('this is a example ()\\rightarrow 2\\pi') text(3.14,sin(3.14),'\\leftarrow this zero for\\pi')
039添加线条标注 x=0:0.2:12;
plot(x,sin(x),'-',x,1.5*cos(x),':'); legend('First','Second',1)
040使用hold on 函数 x=0:0.2:12;
22
plot(x,sin(x),'-'); hold on
plot(x,1.5*cos(x),':');
041一界面多幅图 x=0:0.05:7; y1=sin(x); y2=1.5*cos(x); y3=sin(2*x);
y4=5*cos(2*x);
subplot(221);plot(x,y1);title('sin(x)') subplot(222);plot(x,y2);title('cos(x)') subplot(223);plot(x,y3);title('sin(2x)') subplot(224);plot(x,y4);title('cos(2x)')
042染色效果图 x=0:0.05:7; y1=sin(x); y2=1.5*cos(x); y3=sin(2*x);
y4=5*cos(2*x);
subplot(221);plot(x,y1);title('sin(x)');fill(x,y1,'r') subplot(222);plot(x,y2);title('cos(x)');fill(x,y2,'b') subplot(223);plot(x,y3);title('sin(2x)');fill(x,y3,'k') subplot(224);plot(x,y4);title('cos(2x)');fill(x,y4,'g')
043特殊坐标图 clc
y=[0,0.55,2.5,6.1,8.5,12.1,14.6,17,20,22,22.1] subplot(221);plot(y); title('线性坐标图');
subplot(222);semilogx(y); title('x轴对数坐标图'); subplot(223);semilogx(y); title('y轴对数坐标图'); subplot(224);loglog(y); title('双对数坐标图')
t=0:0.01:2*pi;
r=2*cos(2*(t-pi/8)); polar(t,r)
23
044特殊函数绘图: fplot('cos(tan(pi*x))',[-0.4,1.4])
fplot('sin(exp(pi*x))',[-0.4,1.4])
045饼形图与条形图:
x=[8 20 36 24 12];
subplot(221);pie(x,[1 0 0 0 1]); title('饼图');
subplot(222);bar(x,'group'); title('垂直条形图');
subplot(223);bar(x,'stack');
title('累加值为纵坐标的垂直条形图'); subplot(224);barh(x,'group'); title('水平条形图');
046梯形图与正弦函数 x=0:0.1:10; y=sin(x);
subplot(121);stairs(x); subplot(122);stairs(x,y);
047概率图 x=randn(1,1000); y=-2:0.1:2; hist(x,y)
048向量图: x=[-2+3j,3+4j,1-7j]; subplot(121);compass(x); rea=[-2 3 1]; imag=[3 4 -7];
subplot(122);feather(rea,imag);
24
049绘制三维曲线图: z=0:pi/50:10*pi; x=sin(z); y=cos(z); plot3(x,y,z)
x=-10:0.5:10; y=-8:0.5:8; [x,y]=meshgrid(x,y);
z=sin(sqrt(x.^2+y.^2))./sqrt(x.^2+y.^2); subplot(221);
mesh(x,y,z);
title('普通一维网格曲面'); subplot(222); meshc(x,y,z);
title('带等高线的三维网格曲面'); subplot(223); meshz(x,y,z);
title('带底座的三维网格曲面'); subplot(224);
surf(x,y,z);
title('充填颜色的三维网格面')
050 带网格二维图 x=0:pi/10:2*pi; y1=sin(x); y2=cos(x);
plot(x,y1,'r+-',x,y2,'k*:') grid on
xlabel('Independent Variable x') ylabel('Dependent Variable y1&y2') text(1.5,0.5,'cos(x)')
051各种统计图
y=[18 5 28 17;24 12 36 14;15 6 30 9]; subplot(221);bar(y) x=[4,6,8];
subplot(222);bar3(x,y) subplot(223);bar(x,y,'grouped') subplot(224);bar(x,y,'stack')
25
…… 此处隐藏:1055字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [综合文档]应答器设备技术规范(征求意见稿)A1
- [综合文档]教师 2012年高考政治试题按考点分类汇
- [综合文档]保险公司的总经理助理竞职演说
- [综合文档]卫生应急大练兵大比武活动考试--题库(
- [综合文档]徐州经济技术开发区总体规划环境影响报
- [综合文档]汉语拼音表(带声调)
- [综合文档]二年级 上 思维训练( 1~18)
- [综合文档]特色学校五年发展规划
- [综合文档]机床经常出现报警“X1轴定位监控”
- [综合文档]《电子技术基础》21.§5—2、3、4 习题
- [综合文档]浙江省深化普通高中课程改革
- [综合文档]CRISP原理 - 图文
- [综合文档]2017年电大社会调查研究与方法形考答案
- [综合文档]浅析建筑施工安全毕业论文
- [综合文档]《回忆我的母亲》名师教案
- [综合文档]装饰装修工程监理规划
- [综合文档]三下乡心得体会-文艺
- [综合文档]柱计算长度系数 - 图文
- [综合文档]全流程思考,提高燃电系统热电转换率--
- [综合文档]2018年嘉定区中考物理一模含答案
- 433M车库门滚动码遥控器
- 8、架空线路施工规范
- 大学四年声乐学习的体会
- 新北师大版五年级数学上册《轴对称再认
- 部编版五年级上册语文第六单元小结复习
- 小学六年级英语形容词用法
- 第2课 抗美援朝保家卫国 课件01(岳麓版
- 2015年天津大学运筹学基础考研真题,考
- 微机计算机控制技术课后于海生(第2版)
- 安全教育实践活动
- Delphi程序设计教程_第1章_Delphi概述
- 第八讲 工业革命与启蒙运动
- 《中华人民共和国药典》2005年版二部勘
- 科粤版九年级化学2.3构成物质的微粒(1)
- 西师大版数学三年级下册《长方形、正方
- ch6_冒泡排序演示
- 第4章 冲裁模具设计
- 浙江中小民营企业员工流失论文[终稿]
- 再议有线数字电视市场营运模式
- 昆明供水工程监理大纲




