1 / 8

MATLAB 程式設計 Learning Arrays and x-y Plotting

MATLAB 程式設計 Learning Arrays and x-y Plotting. 方煒 台大生機系. Ex4_2 xy Plots, Labels, and Titles. dx=.01; x=.5*dx:dx:10-0.5*dx; y=sin(5*x); plot(x,y, ’ r- ’ ); nhalf=ceil(length(x)/2); plot(x(1:nhalf),y(1:nhalf), ’ b- ’ ) plot(x(nhalf:end),y(nhalf:end), ’ b- ’ ) xlabel( ’ theta ’ )

hada
Download Presentation

MATLAB 程式設計 Learning Arrays and x-y Plotting

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 程式設計Learning Arrays and x-y Plotting 方煒 台大生機系

  2. Ex4_2 xy Plots, Labels, and Titles • dx=.01; • x=.5*dx:dx:10-0.5*dx; • y=sin(5*x); • plot(x,y,’r-’); • nhalf=ceil(length(x)/2); • plot(x(1:nhalf),y(1:nhalf),’b-’) • plot(x(nhalf:end),y(nhalf:end),’b-’) • xlabel(’\theta’) • ylabel(’F(\theta)’) • title(’F(\theta)=sin(5 \theta)’) • s=sprintf(’F(\\theta)=sin(%i \\theta)’,5) • title(s)

  3. Ex4_3 Overlaying Plots • close • y2=cos(x); % the second function • % plot both • plot(x,y,’r-’,x,y2,’b-’) • close all; • plot(x,y,’r-’) • hold on • plot(x,y2,’b-’) • Hold off

  4. Ex4_4 xyz Plots: Curves in 3-D Space • clear;close all; • dphi=pi/100; % set the spacing in azimuthal angle • N=30; % set the number of azimuthal trips • phi=0:dphi:N*2*pi; • theta=phi/N/2; % go from north to south once • r=1; % sphere of radius 1 • % convert spherical to Cartesian • x=r*sin(theta).*cos(phi); • y=r*sin(theta).*sin(phi); • z=r*cos(theta); • % plot the spiral • plot3(x,y,z,’b-’) • axis equal

  5. Ex4_5 Logarithmic Plots • x=0:.1:8; • y=exp(x); • semilogx(x,y); • title(’Semilogx’) • pause • semilogy(x,y); • title(’Semilogy’) • pause • loglog(x,y); • title(’Loglog’)

  6. Ex4_6 Generating Multiple Plots • x=0:.01:20; • f1=sin(x); • f2=cos(x)./(1+x.^2); • figure • plot(x,f1) • figure • plot(x,f2)

  7. Ex4_7 Controlling the Axes • close all; • x=.01:.01:20; • y=cos(x)./x; • plot(x,y) • axis([0 25 -5 5]) • plot(x,y) • xlim([ 0 25]) • plot(x,y) • ylim([-5 5]) • axis equal

  8. Ex4_8 Greek Letters, Subscripts, and Superscripts • \alpha \beta \gamma \delta \epsilon \phi • \theta \kappa \lambda \mu \nu \pi • \rho \sigma \tau \xi \zeta • Θ1 is coded with \theta_1 • Θ12 is coded with \theta {12} • Θ10is coded with \theta ^{10} • text(10,.5,’Hi’);

More Related