330 likes | 763 Views
Matlab. Early Introduction. Outline. Download Installation Simple guide Loop Condition Solve Plot Animation. Download. Download. Download. Download. Download. Download point 1. Installation guide pdf. Installation. Installation. Installation. Installation.
E N D
Matlab Early Introduction
Outline • Download • Installation • Simple guide • Loop • Condition • Solve • Plot • Animation
Download Download point 1 Installation guide pdf
Installation CD KEY 2013a: 05181-58047-50065-55129-39119-05118-39891-26395-09346-10758-43576-63951-11422-27452-30255-09479
Simple guide(command window) • >> 1+3/2 %simple guide ans = 2.5000 • >> 1+3/2+2*2; • >> x=3*3 x = 9
Simple guide(matrix&vector) >> s = [1 3 5 2]; % The number is separated by “space”. >> t = 2*s+1 t = 3 7 11 5 ************************************************************ >> A = [1 2 3 4; 5 6 7 8; 9 10 11 12]; % build a3×4 matrixA >> A % Show the content of A A = 1 2 3 4 5 6 7 8 9 10 11 12
Simple guide(matrix&vector) >> AT=A‘ % AT is transporse of A AT = 1 5 9 2 6 10 3 7 11 4 8 12
Simple guide(path of mfile) • >> addpath('D:\personal objects\HW\college\Matlab');
Loop • While Loop:
Loop • For Loop
Condition • If
Solve(linear) >>syms x; >>solve(x^4 + 1 == 2*x^2 - 1)ans = (1 + i)^(1/2) (1 - i)^(1/2) -(1 + i)^(1/2) -(1 - i)^(1/2)
Plot clear all; t=0:0.01:3; h=0.01; i=1; while t(i)<3 y(i)=t(i)^2-2*t(i)+1; i=i+1; end y(i)=t(i)^2-2*t(i)+1; plot(t,y); hold on; % Hold the plot plot(t,cos(t),'red');
Plot(axis) • axis([xmin, xmax, ymin, ymax]); • For example:>>axis([-2,2 ,-2,2]);
Plot(label) clear all; t=0:0.01:3; h=0.01; i=1; while t(i)<3 y(i)=t(i)^2-2*t(i)+1; i=i+1; end y(i)=t(i)^2-2*t(i)+1; plot(t,y); hold on; % Hold the plot plot(t,cos(t),'red'); xlabel('X'); ylabel('Y');
Animation t=0:0.01:10; x=0:0.01:5; h=0.01; j=1; while t(j)<10 i=1; while x(i)<5 y(i)=x(i)*sin(5*x(i)-5*t(j)); i=i+1; end y(i)=x(i)*sin(5*x(i)-5*t(j)); plot(x,y); axis([0,5,-5,5]); M(j)=getframe j=j+1; end
Animation i=1; while x(i)<5 y(i)=x(i)*sin(5*x(i)-5*t(j)); i=i+1; end y(i)=x(i)*sin(5*x(i)-5*t(j)); plot(x,y); M(:,length(t))=getframe; movie(M,3) %play the animation movie2avi(M,'exampleformovie.avi','compression','None');