原則。
1. f x( )x46x37x3, 7 x 4
Ans:
>> x=linspace(-7,4,100);y=x.^4+6*x.^3+7*x+3;
>> plot(x,y)
2. f x( ) 6sin( x3)cosx , 2
x
Ans:
>> x=linspace(-pi,2*pi,100);y=6*sin(x+3).*cos(x);
>> plot(x,y)
3. ( ) 2 3 1 f x x
x
, 3 x 6
Ans:
>> x=linspace(-3,6,100);
>> y=(x+3)./(x.^2+1);
>> plot(x,y)
4. f x( ) cosh xsinh(2 )x , 5 x 5
Ans:
>> x=linspace(-5,5,100);
>> y=cosh(x)+sinh(2*x);
>> plot(x,y)
5. ( ) 2 0 2 (cos( d ) cos( ))
d
y t f
t
t
,
1.1,
d1, f00.1, 0 t 1306. y t( )etsin(3t2), 0 t 4
Ans:
>> t=linspace(0,4,100);
>> y=exp(-t).*sin(3*t+2);
>> plot(t,y)
5.2 繪圖區域的控制
7. 試依序回答下面的問題(請利用 axis() 指令來設定繪圖的範圍):
(a) 繪製y x( )x46x37x 的圖形,範圍請用 73 ; 200x 4 y 400。
(b) 設定(a)所繪的圖形要顯示格線,並除去外框。
(c) 設定(b)所繪的圖形,其圖形的寬高比為 1:1。
Ans:
(a) >> x=linspace(-7,4,100);
>> y=x.^4+6*x.^3+7*x+3;
>> plot(x,y)
>> axis([-7,4,-200,400])
(b) >> grid on
>> box off
(c) >> axis square
8. 試將 ( ) sinf x x與f x( ) cos x繪製於同一張圖上,範圍請用0 x 2
。Ans:
>> x=linspace(0,2*pi,100);
>> y1=sin(x);
>> y2=cos(x);
>> plot(x,y1,'-rs')
>> hold on
>> plot(x,y2,'-bo')
>> hold off
9. 試繪出 f x1( ) sin x、 f x2( ) sin(2 ) x 、 f x3( ) sin(3 ) x 與 f x4( ) sin(4 ) x 的圖形,繪圖 範圍請用0 x 2
,並將它們排成2 2 的圖形陣列,即排成如下的格式:sin sin(2 ) sin(3 ) sin(4 )
x x
x x
Ans:
>> x=linspace(0,2*pi,100);
>> subplot(2,2,1)
>> plot(x,sin(x))
>> subplot(2,2,2)
>> plot(x,sin(2*x))
>> subplot(2,2,3)
>> plot(x,sin(3*x))
>> subplot(2,2,4)
>> plot(x,sin(4*x))
10. 試繪出 f x1( ) sin x、f x2( ) cos(2 ) x 與f x3( ) tan(3 ) x 的圖形,繪圖範圍0 x 2
, 並將它們排成3 1 的圖形陣列,即排成如下的格式:sin cos tan x x x
Ans:
>> x=linspace(0,2*pi,100);
>> subplot(3,1,1),plot(x,sin(x))
>> subplot(3,1,2),plot(x,cos(2*x))
>> subplot(3,1,3),plot(x,tan(3*x))
5.3 於圖形內加入文字
11. 試繪出 ( ) sin /(f x x x1)
,
0 x 2 的圖形,圖形的標題請用 'my plot',x 軸的文 字解說請用 'time',y 軸的文字解說請用 'speed'。
Ans:
>> x=linspace(0,2*pi,100);
>> y=sin(x)./(x+1);
>> plot(x,y)
>> title('my plot')
>> xlabel('time')
>> ylabel('speed')
12.
試繪出 f x1( )e0.5sinx,
0 x 與
f x2( )e0.5cosx,
0 x 的圖形。請將這兩
張圖繪製於同一張圖內,並用 legend() 指令加入圖例標記(圖形的標記符號請自
訂)。
Ans:
>> x=linspace(0,pi,100);
>> y1=exp(-0.5)*sin(x); y2=exp(-0.5)*cos(x);
>> plot(x,y1,'-rs',x,y2,'-bo')
>> legend('exp(-0.5)*sin(x)','exp(-0.5)*cos(x)',3)
5.4 更簡潔的繪圖指令
13. 試利用 fplot() 指令繪製下列的圖形:
(a) sin ( ) x
f x x ,範圍請用 20 x 20。
(b) f x( ) sin 2xsinx ,範圍請用 4 。 x 4
Ans:
(a) >> fplot('sin(x)/x',[-20,20])
-20 -15 -10 -5 0 5 10 15 20
-0.4 -0.2 0 0.2 0.4 0.6 0.8 1
(b) >> fplot('sin(x)^2*sin(x)',[-4,4])
14. 試利用 ezplot() 指令繪製下列的圖形:
(a) f x( )x46x37x ,範圍請用 73 ; 200x 4 y 400。 (b) f x y( , ) sin ycos(x y ) 1 ,範圍請用 5 ; 2x 2 。 y 4
Ans:
(a) >> ezplot('x^4+6*x^3+7*x+3',[-7,4,-200,400])
於本例中,ezplot 的繪圖的結果似乎不太平滑,但是如果只指定 x 軸方向的範 圍,則可得到較佳的結果:
>> ezplot('x^4+6*x^3+7*x+3',[-7 4])
(b) >> ezplot('sin(y)+cos(x+y)-1',[-5,2,-2,4])
5.5 利用「屬性編輯區」來編修圖形
15. 試依序回答下面的問題:
(a) 試利用 plot() 指令繪製 f x( )e0.5xcos( )x , 0 x ,繪圖點數取 50 個。
(b) 試利用「屬性編輯區」將函數曲線更改為紅色的虛線,資料點的位置以大小為20 的藍色實心小圓來表示。
(c) 試 利 用 「 屬 性 編 輯 區 」 加 上 圖 形 的 標 題 , 標 題 名 稱 為 'my plot', 字 體 為 Helvetica,大小為 14,斜體。
Ans:
(a) >> x=linspace(0,4,50);
>> y=exp(-0.5*x).*cos(3*x);
>> plot(x,y)
(b) 請在Property Editor 視窗中進行如下的設定:
(c) 請在Property Editor 視窗中進行如下的設定:
16. 試依序回答下面的問題:
(a) 試利用 fplot() 指令繪製函數 ( )f x xcos( )x 與g x( )xsin( )x 的圖形於同一個 視窗內,繪圖範圍取0 x 18。
(b) 試利用「屬性編輯區」將
f x ( )
的圖形改成紅色,g x ( )
的圖形更改為紫色,線條粗細為3.0。
(c) 加入圖形的註解,其中
f x ( )
的註解為xcos( )x ,g x ( )
的註解為xsin( )x 。 (d) 加上圖形的外框與網格線。(e) 加上圖形的標題,標題名稱為 Function plots,字體為 Helvetica,大小為 16。
(f) 設定 x 軸的文字解說為 x,y 軸的文字解說為
f x ( ) & ( ) g x
。Ans:
(a) >> fplot('x*cos(x)',[0,18])
>> hold on
>> fplot('x*sin(x)',[0,18])
0 2 4 6 8 10 12 14 16 18 -20
(b) >>請在 Property Editor 視窗中進行如下的設定:
0 2 4 6 8 10 12 14 16 18
-20 -15 -10 -5 0 5 10 15
(c) >>請在 Property Editor 視窗中進行如下的設定:
(d) >> box on; grid on
0 2 4 6 8 10 12 14 16 18
-20 -15 -10 -5 0 5 10 15
x sin(x) x cos(x)
(e) >>請在 Property Editor 視窗中進行如下的設定:
0 5 10 15 -20
-15 -10 -5 0 5 10
15 Function plots
x sin(x) x cos(x)
(f) >>請在 Property Editor 視窗中進行如下的設定:
0 5 10 15 -20
-15 -10 -5 0 5 10 15
f(x)
g(x)
Function plots
x sin(x) x cos(x)