1 / 40

MATLAB 绘图

MATLAB 绘图. 二维图形. MATLAB 绘图. 符号函数画图 —ezplot & fplot ezplot(f,[a,b]) % 默认区间为 [-2pi, 2pi] ezplot(f,[xmin,xmax,ymin,ymax]) ezplot(x,y) % 在默认区间 0<t<2pi, 绘制 x=x(t),y=y(t) 的函数图。 ezplot(x,y,[tmin,tmax]). MATLAB 绘图. ezplot('cos(x)') ezplot('cos(x)', [0, pi])

marah-weiss
Download Presentation

MATLAB 绘图

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLAB绘图 二维图形

  2. MATLAB绘图 • 符号函数画图—ezplot & fplot ezplot(f,[a,b]) % 默认区间为 [-2pi, 2pi] ezplot(f,[xmin,xmax,ymin,ymax]) ezplot(x,y) %在默认区间0<t<2pi,绘制x=x(t),y=y(t)的函数图。 ezplot(x,y,[tmin,tmax])

  3. MATLAB绘图 ezplot('cos(x)') ezplot('cos(x)', [0, pi]) ezplot('1/y-log(y)+log(-1+y)+x - 1') ezplot('x^2 - y^2 - 1') ezplot('x^2 + y^2 - 1',[-1.25,1.25]); axis equal ezplot('x^3 + y^3 - 5*x*y + 1/5',[-3,3]) ezplot('x^3 + 2*x^2 - 3*x + 5 - y^2') ezplot('sin(t)','cos(t)') ezplot('sin(3*t)*cos(t)','sin(3*t)*sin(t)',[0,pi]) ezplot('t*cos(t)','t*sin(t)',[0,4*pi])

  4. Fplot 绘制函数在指定函数区间的图形 fplot(fun,lims,tol) %lims=[xmin,xmax] tol 默认为0.002. fplot('sin(1 / x)', [0.01 0.1],1e-3)

  5. MATLAB绘图 fplot(fun,lims,tol) % fun 必须是m文件或者独立变量为x的字符串,如果fun为[f1(x),f2(x),f3(x)],则当输入[x1,x2]后,返回的是矩阵[f1(x1),f2(x1),f3(x1) f1(x2),f2(x2),f3(x2)] fplot('[tan(x),sin(x),cos(x)]',2*pi*[-1 1 -1 1])

  6. f = inline('abs(exp(-j*x*(0:9))*ones(10,1))'); fplot(f,[0 2*pi])

  7. MATLAB绘图 • 画点 plot(2,4, 'r*') • 画线 plot([0 1],[0 2]) x=2:2:8; plot([x;x],[zeros(1,length(x));cos(pi*x/20)], 'k') %axis([0 10 0 1])

  8. MATLAB绘图 画圆 theta=linspace(0,2*pi); plot(1+0.5*cos(theta),2+0.5*sin(theta)) axis equal %使图形对称 如何画具有不同半径的同心圆?

  9. MATLAB绘图 • 函数相对另一函数的图形绘制 theta=linspace(0,2*pi,101); plot(sin(theta),sin(2*theta+pi/4)) % 里萨如图形 axis off %隐去坐标轴

  10. MATLAB绘图 • 曲线族的绘制 例, 抛物线族 y =a^2-x^2, -5<x<5, a=1,2…5. x=-5:0.2:5; a=1:5; [xx,aa]=meshgrid(x.^2,a.^2); plot(x,aa-xx,’k’)

  11. MATLAB绘图

  12. MATLAB绘图 • 在一个图形界面中绘制多条曲线 y = 0.1*x^2 y=cos(x)^2 y=exp(-0.3x) x=linspace(0,3.5); plot(x,0.1*x.^2,’k’) hold on plot(x,cos(x).^2,’k’) plot(x,exp(-0.3*x),’k’)

  13. MATLAB绘图 • 基本二维绘图函数plot t=0:.1:2*pi; y=sin(t); plot(t,y) ,pause t=0:.1:2*pi; y=[sin(t); cos(t)]; plot(t,y) ,pause t=0:.1:2*pi; plotyy(t,sin(t),t,0.01*cos(t)) ,pause t=0:.1:2*pi; y=[sin(t); cos(t)]; plot(t,y) ,pause plot(t,sin(t),t,cos(t)) ,pause t=0:.1:2*pi; y1=sin(t); y2=cos(t); y3=sin(t).*cos(t); ,pause plot(t,y1,'-',t,y2,':',t,y3,'x') grid, xlabel('This is my X axis'), ylabel('My Y axis'), title('My First Plot')

  14. MATLAB绘图 • 图形注释和可视化提高 • 使用坐标轴,图形标题,曲线标注,填充区域和添加文本 • 改变轴、曲线和文本的属性 • 使用希腊字母、数学符号、上下标等

  15. MATLAB绘图 例 x=0:0.05:6; plot(x,cos(x),'k',x,1./cosh(x),'k',[4.73 4.73],[-1 1],'k') xlabel('x') ylabel('value of function') title('visualizaton of two intersecting curves') text(4.8,-.5,'x=4.73') text(2.1,.3,'1/cosh(x)') text(1.2,-.4,'cos(x)')

  16. MATLAB绘图 • 加图例—legend函数 legend函数不同于text函数,因为text函数可多次使用,而legend函数却只可用一次。Legend函数的参数个数与一个或多个plot函数绘制的不同线段个数相等。 x=0:.05:6; plot(x,cos(x), 'k-',x,1./cosh(x), 'k --') legend('cos(x) ', '1/cosh(x) ',3)

  17. MATLAB绘图 • plot中属性设置 x=-pi:pi/10:pi; y=tan(sin(x))-sin(tan(x)); plot(x,y,'-- rs', 'LineWidth',2, … 'MarkerEdgeColor','k', … 'MarkerFaceColor','g', … 'MarkerSize',10)

  18. MATLAB绘图 LineWidth 指定线条的粗细 MarkerEdgeColor 指定标记的颜色或填充标记(圆形,方形,金刚石形等)的边缘色 MarkerFaceColor 指定填充标记表面的颜色 MarkerSize 以点集为单位指定标记的大小

  19. MATLAB绘图 • set函数 x=0:.05:6; h=plot(x,cos(x),'k',x,1./cosh(x),'k',[4.73 4.73],[-1 1],'k'); text(4.8,-.5,'x=4.73','fontname','times','fontsize',14) text(2.1,.3,'1/cosh(x)','fontsize',16) text(1.2,-.4,'cos(x)','fontsize',16,'fontname','times') set(gca,'fontsize',14,'LineWidth',2) PropertyName={'LineWidth','LineWidth','LineWidth'}; PropertyValue={2.5,2.5,2.5;7,7,7;1,1,1}; set(h,PropertyName,PropertyValue) [legendhandle objecthandle]=legend('cos(x)','1/cosh(x)',3); set(objecthandle(1),'fontsize',14,'color','r')

  20. MATLAB绘图 • 调整坐标轴度量标记的位置和标签 x=-pi:.1:pi; y=sin(x); plot(x,y) set(gca, 'XTick',-pi:pi/2:pi) set(gca, 'XTickLabel',{'-pi', '-pi/2', '0', 'pi/2', 'pi'})

  21. x=0:.05:6; h=plot(x,cos(x),‘-b',x,1./cosh(x),‘--r',[4.73 4.73],[-1 1],'k'); xlabel('x'); ylabel('Value of Function') title('Visualization of two intersectting curves') text(4.8,-.5,'x=4.73','fontname','times','fontsize',14) text(2.1,.3,'1/cosh(x)','fontsize',16) text(1.2,-.4,'cos(x)','fontsize',16,'fontname','times') set(gca,'fontsize',14,'LineWidth',2) PropertyName={'LineWidth','LineWidth','LineWidth'}; PropertyValue={2.5,2.5,2.5;7,7,7;1,1,1}; set(h,PropertyName,PropertyValue) [legendhandle objecthandle]=legend('cos(x)','1/cosh(x)',3); set(objecthandle(1),'fontsize',14,'color','r')

  22. MATLAB绘图 • 增加希腊字母、上标下标和数学符号对图形进行注释 Omega1=linspace(1,2); beta=3; plot(Omega1,1+exp(-Omega1.^beta),'k') title('Plot of g_2 versus \Omega_1 for \beta=3') ylabel('g_2') xlabel('\Omega_1') text(1.2,1.2,'g_2=1+e^{-\Omega_1^\beta}','fontsize',16)

  23. MATLAB绘图 t=['\partial(f_ip)/\partialt=-\Sigma_{i=1}^n\partial(f_ip)/\partialx_i',... ' + 0.5\Sigma_{i=1}^n\Sigma_{j=1}^n\partial^2(b_{ij}p)/',... '\partialx_i\partialx_j']; gtext(t); gtext('Y(\omega)=\int_0^\infty y(t)e^{-j\omegat}dt'); t=['\partial(f_ip)/\partialt=-\Sigma_{i=1}^n\partial(f_ip)/\partialx_i',... ' + 0.5\Sigma_{i=1}^n\Sigma_{j=1}^n\partial^2(b_{ij}p)/',... '\partialx_i\partialx_j']; tt=str2mat(t,'Y(\omega)=\int_0^\infty y(t)e^{-j\omegat}dt'); [x,y]=ginput(1); text(x,y,tt)

  24. MATLAB绘图 • 作业 • 施加在弹簧上的力与C1成比例,其中 C1=0.5dt^3-1.5ht*dt^2+(1+ht^2)dt ht=h/t, dt=d/t, d为弹簧的挠度。当ht在1~3之间变化,增量为0.25,且dt在0~5之间变化时,画出C1随dt变化的曲线,标注曲线,并令y极限为8。结果如图

More Related