matlab画图.docx
- 文档编号:10622869
- 上传时间:2023-02-21
- 格式:DOCX
- 页数:46
- 大小:1.79MB
matlab画图.docx
《matlab画图.docx》由会员分享,可在线阅读,更多相关《matlab画图.docx(46页珍藏版)》请在冰豆网上搜索。
matlab画图
p0_4subplot.m
%程序的顺序结构
clear
a=0:
10:
360
x=a*pi/180
figure
subplot(1,2,1)
plot(a,tan(x),'linewidth',2)
axis([0,360,-5,5])
subplot(1,2,2)
plot(a,cot(x),'linewidth',2)
axis([0,360,-5,5])
P0_5if.m
%程序的单分支结构和双分支结构
clear
c1=input('画正弦线选1,其它数值画正切线:
');
x=(0:
5:
360)*pi/180
ifc1==1
y=sin(x)
else
y=tan(x)
end
c2=input('横坐标取度数选择1,其它数值取弧度数:
');
ifc2==1
x=x*180/pi
end
figure
plot(x,y,'linewidth',2)
ifc1~=1
ifc2==1
axis([0,360,-5,5])
else
P0_6_1if_elseif.m
%程序的多分支结构
clear
c=input('请选择(1正弦线,2余弦线,3正切线,4余切线');
x=(0:
5:
360)*pi/180
figure
%-----------------------------------------------------------------
ifc==1
plot(x,sin(x),'linewidth',2)
elseifc==2
plot(x,cos(x),'linewidth',2)
elseifc==3
plot(x,tan(x),'linewidth',2)
elseifc==4
plot(x,cot(x),'linewidth',2)
else
close
return
end
%-----------------------------------------------------------------
ifc==3||c==4
axis([0,2*pi,-5,5])
end
P_0_6switch.m
%程序的多分支结构开关控制
clear
c=input('请选择(1正弦线,2余弦线,3正切线,4余切线):
');
x=(0:
5:
360)*pi/180
figure
%-----------------------------------------------------------------
switchc
case1
plot(x,sin(x),'linewidth',2)
case2
plot(x,cos(x),'linewidth',2)
case3
plot(x,tan(x),'linewidth',2)
case4
plot(x,cot(x),'linewidth',2)
otherwise
close
return
end
%-----------------------------------------------------------------
ifc<1||c>4,return,end
Y=[sin(x);cos(x);tan(x);cot(x)];
plot(x,Y(c,:
),'linewidth',2)
%--------------------------------------------------------------------
P0_7logic.m
%逻辑运算-半波整流和全波整流
clear,x=(0:
10:
720)*pi/180;y=sin(x);
i=y<0
y(i)
y(i)=0
figure
subplot(2,1,1),plot(x,y,x,sin(x),'--','linewidth',2)
title('半波整流')
y=sin(x)
y(y<0)=-y(y<0)
subplot(2,1,2),plot(x,y,x,sin(x),'--','linewidth',2)
title('全波整流')
x=
Columns1through9
00.08730.17450.26180.34910.43630.52360.61090.6981
Columns10through18
0.78540.87270.95991.04721.13451.22171.30901.39631.4835
Columns19through27
1.57081.65811.74531.83261.91992.00712.09442.18172.2689
Columns28through36
2.35622.44352.53072.61802.70532.79252.87982.96713.0543
Columns37through45
3.14163.22893.31613.40343.49073.57793.66523.75253.8397
Columns46through54
3.92704.01434.10154.18884.27614.36334.45064.53794.6251
Columns55through63
4.71244.79974.88694.97425.06155.14875.23605.32335.4105
Columns64through72
5.49785.58515.67235.75965.84695.93416.02146.10876.1959
Column73
6.2832
i=
Columns1through16
0000000000000000
Columns17through32
0001111111111111
Columns33through48
1111100000000000
Columns49through64
0000000111111111
Columns65through73
111111111
ans=
Columns1through9
-0.1736-0.3420-0.5000-0.6428-0.7660-0.8660-0.9397-0.9848-1.0000
Columns10through18
-0.9848-0.9397-0.8660-0.7660-0.6428-0.5000-0.3420-0.1736-0.0000
Columns19through27
-0.1736-0.3420-0.5000-0.6428-0.7660-0.8660-0.9397-0.9848-1.0000
Columns28through36
-0.9848-0.9397-0.8660-0.7660-0.6428-0.5000-0.3420-0.1736-0.0000
y=
Columns1through9
00.17360.34200.50000.64280.76600.86600.93970.9848
Columns10through18
1.00000.98480.93970.86600.76600.64280.50000.34200.1736
Columns19through27
0.000000000000
Columns28through36
000000000
Columns37through45
00.17360.34200.50000.64280.76600.86600.93970.9848
Columns46through54
1.00000.98480.93970.86600.76600.64280.50000.34200.1736
Columns55through63
0.000000000000
Columns64through72
000000000
Column73
0
y=
Columns1through9
00.17360.34200.50000.64280.76600.86600.93970.9848
Columns10through18
1.00000.98480.93970.86600.76600.64280.50000.34200.1736
Columns19through27
0.0000-0.1736-0.3420-0.5000-0.6428-0.7660-0.8660-0.9397-0.9848
Columns28through36
-1.0000-0.9848-0.9397-0.8660-0.7660-0.6428-0.5000-0.3420-0.1736
Columns37through45
-0.00000.17360.34200.50000.64280.76600.86600.93970.9848
Columns46through54
1.00000.98480.93970.86600.76600.64280.50000.34200.1736
Columns55through63
0.0000-0.1736-0.3420-0.5000-0.6428-0.7660-0.8660-0.9397-0.9848
Columns64through72
-1.0000-0.9848-0.9397-0.8660-0.7660-0.6428-0.5000-0.3420-0.1736
Column73
-0.0000
y=
Columns1through9
00.17360.34200.50000.64280.76600.86600.93970.9848
Columns10through18
1.00000.98480.93970.86600.76600.64280.50000.34200.1736
Columns19through27
0.00000.17360.34200.50000.64280.76600.86600.93970.9848
Columns28through36
1.00000.98480.93970.86600.76600.64280.50000.34200.1736
Columns37through45
0.00000.17360.34200.50000.64280.76600.86600.93970.9848
Columns46through54
1.00000.98480.93970.86600.76600.64280.50000.34200.1736
Columns55through63
0.00000.17360.34200.50000.64280.76600.86600.93970.9848
Columns64through72
1.00000.98480.93970.86600.76600.64280.50000.34200.1736
Column73
0.0000
P0_8for.m
%程序的固定循环结构
clear,a=0:
360;x=a*pi/180;
yt=tan(x);
yt(abs(yt)>10)=nan
yc=cot(x);yc(abs(yc)>10)=nan
YC={sin(x),cos(x),yt,yc};
tc={'sin','cos','tan','cot'};
figure
fori=1:
4
subplot(2,2,i)
plot(a,YC{i},'linewidth',2)
title(tc{i})
xlabel(‘\itx’)
end
P0_9forfor1.m
%程序的双重循环结构
clear,n=input('请输入圆柱的层数:
');
phi=linspace(0,2*pi);x=cos(phi);y=sin(phi);
figure,title('堆叠的圆(柱)','FontSize',16)
axisequal,holdon
fori=1:
n
forj=1:
i
plot(x+2*j,y-2*i)
end
end
P0_9forfor2.m
%程序的双重循环结构
clear,n=input('请输入圆柱的层数:
');
phi=linspace(0,2*pi);x=cos(phi);y=sin(phi);
figure,title('堆叠的圆(柱)','FontSize',16)
axisequal,holdon
fori=1:
n
forj=1:
i
plot(x-2*i,y+2*j)
end
end
P0_9forfor3.m
%程序的双重循环结构
clear,n=input('请输入圆柱的层数:
');
phi=linspace(0,2*pi);x=cos(phi);y=sin(phi);
figure,title('堆叠的圆(柱)','FontSize',16)
axisequal,holdon
fori=1:
n
forj=1:
i
plot(x+2*j-i,y-sqrt(3)*i)
end
end
P0_9forfor4.m
%程序的双重循环结构
clear,n=input('请输入圆柱的层数:
');
phi=linspace(0,2*pi);x=cos(phi);y=sin(phi);
figure,title('堆叠的圆(柱)','FontSize',16)
axisequal,holdon
fori=1:
n
forj=1:
i
plot(x+2*j-i,y+sqrt(3)*i)
end
end
%等量异号点电荷的电势分布
clear
[x,y]=meshgrid(-5:
0.2:
5,-4:
0.2:
4);
z=1./sqrt((x-2).^2+y.^2+0.01)-1./((x+2).^2+y.^2+0.01);
mesh(x,y,z)
matlab中的汉字粘贴到word里怎么是乱码?
要写报告时,从MATLAB中复制出的程序中的汉字注释全部是乱码,这怎么办啊?
以前也好好的啊!
请高手帮忙啊,谢谢!
问题补充:
粘贴到txt中,然后再粘贴到word中那些MATLAB中的注释的颜色都变了,其实不但是放到word中乱码,就算是复制到QQ对话框中也是乱码的,故应该是更改MATLAB的中的某项设置。
一个很好的方法是你先把matlab中的文字粘贴到txt中,然后再粘贴到word中就可以了,不过字体稍有变化。
因为word中没有matlab的那种字体。
你的提问也促使我去找解决方法。
我试了一下。
你可以把matlab中的字体设置一下。
你设置称宋体之类的就是了。
File--preference-fonts--custom--你选editor然后旁边选custom,然后找你的字体吧。
选宋体之类的都可以!
我试了的你自己去看一下!
!
P0_10while.m
%超越方程的迭代算法
clear%清除变量
x0=1;%初始值
xx=[];%空向量
%xx=x0;%保留初始值
while1%无限循环
x=5*(1-exp(-x0));%迭代运算
%x=log(1/(1-x0/5));%迭代运算(向0收敛)
xx=[xx,x];%连接结果
iflength(xx)>1000,return,end%如果项数太多则退出程序的执行
ifabs(x0-x)<1e-4,break,end%当精度足够高时退出循环
x0=x;%替换初值
end%结束循环
x0=x;%保存结果
figure%创建图形窗口
subplot(1,2,1)%选子图
plot(xx,'x-','LineWidth',2)%画迭代线
gridon%加网格
fs=16;%字体大小
title('超越方程的迭代折线','FontSize',fs)%标题
xlabel('\itn','FontSize',fs)%x标签
ylabel('\itx','FontSize',fs)%y标签
text(length(xx),x0,num2str(x0),'FontSize',fs)%显示结果
x=0:
0.01:
8;%自变量向量
subplot(1,2,2)%选子图
plot(x,x,x,5*(1-exp(-x)),'--','LineWidth',2)%画直线和指数函数曲线
holdon%保持图像
plot(x0,x0,'o')%画直线和指数函数的交点
gridon%加网格
title('直线与指数函数的交点','FontSize',fs)%标题
xlabel('\itx','FontSize',fs)%x标签
ylabel('\ity','FontSize',fs)%y标签
text(x0,x0,num2str(x0),'FontSize',fs)%显示结果
p0_11_1function.m
%求一元二次方程的函数文件
function[x1,x2]=fun(a,b,c)%定义函数文件
d=b^2-4*a*c;%根的判别式
x1=(-b+sqrt(d))/2/a;%求第一个根
x2=(-b-sqrt(d))/2/a;%求第二个根
P0_11_2varargin.m
%求一元二次方程和一次方程的函数文件
functionvarargout=fun(varargin)
switchnargin%¿ª¹ØÑ¡Ôñ
case3%Èç¹ûÓÐ3¸öÊäÈë²ÎÊý
a=varargin{1};%È¡¶þ´ÎÏîϵÊý
b=varargin{2};%È¡Ò»´ÎÏîϵÊý
c=varargin{3};%È¡³£ÊýÏî
d=b^2-4*a*c;%¼ÆËã¸ùµÄÅбðʽ
varargout{1}=(-b+sqrt(d))/2/a;%ÇóµÚÒ»¸ö¸ù
varargout{2}=(-b-sqrt(d))/2/a;%ÇóµÚ¶þ¸ö¸ù
case2%Èç¹ûÓÐ2¸öÊäÈë²ÎÊý
b=varargin{1};%È¡Ò»´ÎÏîϵÊý
c=varargin{2};%È¡³£ÊýÏî
varargout{1}=-b/c;%ÇóÒ»´Î·½³ÌµÄ½â
otherwise%ÆäËûÇé¿ö
varargout{1}=nan;%Êä³ö·ÇÊý±íʾÎÞ½â
end%Í˳ö¿ª¹Ø
p0_12_1stem.m
%函数曲线的绘制和极值的标记
clear%清除变量
a=-0.5;%指数的系数
b=2;%正弦项的系数
x=0:
0.01:
10;%自变量向量
y=exp(a*x).*sin(b*x);%函数向量
figure%开创图形窗口
plot(x,y,'LineWidth',2)%补画曲线
gridon%加网格
title('函数曲线','FontSize',16)%加标题
xlabel('横坐标\itx','FontSize',16)%加横坐标标签
ylabel('纵坐标\ity','FontSize',16)%加纵坐标标签
text(5,0.8,'\ity\rm=e^{\itax}\rmsin\itbx','FontSize',16)%显示公式
txt=['\ita\rm=',num2str(a),',\itb\rm=',num2str(b)];%参数文本
text(5,0.6,txt,'FontSize',16)%显示参数
[ym,im]=max(y);%求函数的最大值和下标
xm=x(im);%求最大值的横坐标
holdon%保持图像
stem(xm,ym,'--','fill')%画极值杆线
txt=['(',num2str(xm),',',num2str(ym),')'];%极值坐标文本
text(xm,ym,txt,'FontSize',16)%显示极值文本
P0_12_2meshgrid.m
%函数曲线族的绘制
clear%清除变量
b=0.5;%正弦项的系数
a=-0.6:
0.1:
0;%指数的系数(参数)
x=0:
0.2:
20;%自变量向量
[A,X]=meshgrid(a,x);%化为自变量和参数矩阵
%[X,A]=meshgrid(x,a);%化为自变量和参数矩阵
Y=exp(A.*X).*sin(b*X);%函数向量
figure%开创图形窗口
plot(x,Y,'LineWidth',2)%画曲线
%plot(X,Y,'LineWidth',2)%画曲线
%plot(X',Y','LineWidth',2)%画曲线
gridon%加网格
tit='(\ity\rm=e^{\itax}\rmsin\itbx\rm)';%公式
title(['函数曲线族',tit],'FontSize',16)%加标题
xlabel('\itx','FontSize',16)%加横坐标标签
ylabel('\ity','FontSize',16)%加纵坐标标签
legend(num2str(a'),4)%图例
%legend([repmat('\ita\rm=',length(a),1),num2str(a')],4)%图例
text(0,-0.5,['\itb\rm=',num2str(b)],'FontSize',16);%显示正弦项的系数
[ym,im]=max(Y);%求函数的最大值和下标
%[ym,im]=max(Y,[],2);%求函数的最大值和下标
xm=x(im);%最大值的横坐标
holdon%保持图像
stem(xm,ym,'--')%画最大值的杆图
a=-1:
0.001:
-0.001;%
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab 画图
![提示](https://static.bdocx.com/images/bang_tan.gif)