1.38k likes | 1.54k Views
第 5 章 繪圖及模型建構 plotting & model building. 圖比表好 表比文字好. xy plotting functions. y=f(x) abscissa ~ x (independent variable) ordinate ~ y (dependent variable) Scale 刻度 tick mark 刻度標示 axis label 軸稱 or axial title data symbol or point marker Legend ~ 說明.
E N D
第5章 繪圖及模型建構plotting & model building Puff! The magic dragon, Live by the sea….
圖比表好 • 表比文字好 Puff! The magic dragon, Live by the sea….
xy plotting functions • y=f(x) • abscissa ~ x (independent variable) • ordinate ~ y (dependent variable) • Scale刻度 • tick mark刻度標示 • axis label 軸稱 or axial title • data symbol or point marker • Legend ~ 說明 Puff! The magic dragon, Live by the sea….
line ~ for theoretical calculation data • data symbol ~ for experimental data Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Requirements of correct plot • P.243-244 • Read it NOW! Puff! The magic dragon, Live by the sea….
Plot, Label & Title commands x=[0:.1:52]; y=.4*sqrt(1.8*x); plot(x,y),xlabel('距離(英里)'),ylabel('距離(英里)'),... title('火箭高度相對於飛行方向的距離函數') grid on, axis([0 52 0 5]) Copy figure Paste it in the word file Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Plot of complex numbers • plot(y)=plot(real(y),imag(y)) %if y is complex z=.1+.9i; n=[0:0.01:10]; plot(z.^n),xlabel('real part'),ylabel('imaginary part') Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
The function plot command fplot • fplot(‘string’,[xmin xmax]) • fplot(‘string’,[xmin xmax ymin ymax]) f='cos(tan(x))-tan(sin(x))'; fplot(f,[1 2]) Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
x=[1:.01:2]; y=cos(tan(x))-tan(sin(x)); plot(x,y) Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Plotting polynomials • x=[-6:0.01:6]; • p=[3,2,-100,2,-7,90]; • plot(x,polyval(p,x)),xlabel('x'),ylabel('p') Puff! The magic dragon, Live by the sea….
Self testing • pp.250-251 • Write down the program now! Puff! The magic dragon, Live by the sea….
Subplot 子圖 subplot(m,n,p) %將視窗分成m列n行的陣列平面 第p平面 x=[0:.01:5]; y=exp(-1.2*x).*sin(10*x+5); subplot(1,2,1) plot(x,y),xlabel('x1'),ylabel('y1'),axis([0 5 -1 1]) x=[-6:.01:6]; y=abs(x.^3-100); subplot(1,2,2) plot(x,y),xlabel('x2'),ylabel('y2'),axis([-6 6 0 350]) Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
overlay plot 層疊圖 • P.253 • A ~ m列*n行 • plot(A) % n條曲線(A的行向量對其索引的圖) • plot(x,A) % A矩陣對x向量作圖 • plot(A,x) % x向量對A矩陣作圖(m條曲線) • plot(A,B) % B矩陣的行對A矩陣的行作圖 Puff! The magic dragon, Live by the sea….
a=[1 2 3;6 5 4;1 5 3] a = 123 6 54 153 ?plot(a) plot(A) % n條曲線(A的行向量對其索引的圖) Puff! The magic dragon, Live by the sea….
x = 10 20 30 40 ?a a = 1 2 3 6 5 4 1 5 3 8 8 8 ?plot(x,a) • plot(x,A) % A矩陣對x向量作圖 Puff! The magic dragon, Live by the sea….
x = 10 20 30 40 ?a a = 1 2 3 6 5 4 1 5 3 8 8 8 ?plot(a,x) plot(A,x) % x向量對A矩陣作圖(m條曲線) Puff! The magic dragon, Live by the sea….
a = 1 2 3 6 5 4 1 5 3 8 8 8 ?b b = 1 2 3 2 4 6 3 6 9 4 8 12 ?plot(a,b) Puff! The magic dragon, Live by the sea….
Data markers and line types Puff! The magic dragon, Live by the sea….
Data markers and line types • plot(x,y,’o’) • plot(x,y,x,y,’o’) Puff! The magic dragon, Live by the sea….
plot(x,y,x,y,’o’) plot(x,y,’o’) Puff! The magic dragon, Live by the sea….
plot(x,y,’ *’,x,y,’:’) Puff! The magic dragon, Live by the sea….
Labeling curves and data x=[0:.01:2]; y=sinh(x); z=tanh(x); plot(x,y,x,z,'--'),xlabel('x'), ... ylabel('Hyperbolic Sine and Tangent'), ... legend('sinh(x)','tanh(x)') Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Legend 的移動 • plot圖出來後 利用滑鼠左鍵移動之 • 格線(grid line)造成legend不明顯 在圖畫好 列印前 加入 axes(legend(‘string1’,‘string2’)) %框與軸線設定一致 refresh %強迫圖形重新繪出 Puff! The magic dragon, Live by the sea….
x=[0:.01:1]; y=tan(x); z=sec(x); plot(x,y,x,z),xlabel('x'), ... ylabel('Tangent and Secant'),gtext('tan(x)'), ... text(.3,1.2,'sec(x)') Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
x=[-30:.01:30]; %求解x=tan(x) y=tan(x); z=6*x; plot(x,y,x,z),xlabel('x'), ... ylabel('6x=tan(x) '), axis([-5 5 -100 100]) [x,y]=ginput(5) Puff! The magic dragon, Live by the sea….
Graphical solution of equations圖解法求解方程式 • Example 5.2-1 load line analysis of a circuit Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
v_2=[0:.01:20]; i_11=.16*(exp(.12*v_2)-1); i_12=-1/30*v_2+.5; plot(v_2,i_11,v_2,i_12), grid,xlabel('v_2(Volts)'),... ylabel('i_1(Ampere)'),axis([0 20 0 1]),... gtext('load line'),gtext('current') Puff! The magic dragon, Live by the sea….
The answer: i1=0.25 Ampere, v2=7.5V Puff! The magic dragon, Live by the sea….
axis([7 8 .2 .3])% room-in view Puff! The magic dragon, Live by the sea….
The hold command • 2 plot commands p.258-259 x=[-1:.01:1]; y1=3+exp(-x).*sin(6*x); y2=4+exp(-x).*cos(6*x); plot((.1+.9i).^[0:.01:10]),hold,plot(y1,y2),... gtext('y2 VS y1'),gtext('Imag(z) VS Real(z)') gtext最好在都plot完之後再執行,以免亂掉 Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Annotating plots 繪圖註解 • Using TEX Puff! The magic dragon, Live by the sea….
Note for improving plots • p.262-263 Puff! The magic dragon, Live by the sea….
Special plot types • Logarithmic plots • Frequency response plots and filter circuits • Controlling tick-mark spacing and labels • Stem, stairs, and bar plots • Separate Y axes • Polar plots Puff! The magic dragon, Live by the sea….
Puff! The magic dragon, Live by the sea….
Logarithmic plots Puff! The magic dragon, Live by the sea….