Você está na página 1de 31

8QLYHUVLW\RI7XUNLVK$HURQDXWLFDO$VVRFLDWLRQ

)DFXOW\RI(QJLQHHULQJ
((( GHSDUWPHQW

(((
'LJLWDO6LJQDO3URFHVVLQJ

 ,QWURGXFWLRQWR0$7/$%

$QNDUD± )HEUXDU\

0DWODEŠ
{ 0DWODE Š LV D VRIWZDUH WRRO RULJLQDOO\ GHYHORSHG DV D ³0DWUL[
/DERUDWRU\´ EXW QRZ XVHG LQ DOPRVW DOO DUHDV RI VFLHQFH DQG
HQJLQHHULQJ

{ 7KLV VRIWZDUH LV XVHG E\ VFLHQWLVWV HQJLQHHUV WHDFKHUV DQG


VWXGHQWV LQ ERWK DFDGHPLF LQVWLWXWHV DQG LQGXVWULHV GHDOLQJ ZLWK
SUREOHP VROYLQJ LQ EDVLF PDWKHPDWLFV JUDSKLFV GLIIHUHQWLDO
HTXDWLRQV HOHFWULFHOHFWURQLF FLUFXLWV VLPXODWLRQ FRQWURO V\VWHPV
DXWRPDWLRQ VLJQDO SURFHVVLQJ LPDJH SURFHVVLQJ VWDWLVWLFV
DHURVSDFH WHOHFRP ELRLQIRUPDWLFV DQG PDQ\ RWKHU DSSOLFDWLRQV

,QWURGXFWLRQWR0$7/$% 2
0DWKHPDWLFDORSHUDWLRQV

{$GG
[\

{6XEWUDFW
[± \

{0XOWLSO\
[ \

{'LYLGH
[\
,QWURGXFWLRQWR0$7/$%

0DWKHPDWLFDORSHUDWLRQV

,QWURGXFWLRQWR0$7/$%
3UHGHILQHGFRQVWDQWV
:KHQ0$7/$%VWDUWVFHUWDLQYDULDEOHQDPHVDUHLQLWLDOL]HGZLWKYDOXHVWKDWDUH
FRPPRQO\UHTXLUHG >> pi
ans =
pi :  3.1416

i : VTUW  >> j

j : VTUW   ans =


0 + 1.0000i
>> i
ans =
0 + 1.0000i

)RUDQ\RIWKHVHSUHGHILQHGYDULDEOHV >> i=5;


>> i
LWLVSRVVLEOHWRRYHUZULWHWKHP i =
5

,QWURGXFWLRQWR0$7/$% 5

7KHFRPPRQEXLOWLQ)XQFWLRQV
ĂďƐ ďƐŽůƵƚĞǀĂůƵĞ
ĐŽƐ ŽŶƐŝŶĞĨƵŶĐƚŝŽŶ
ƐŝŶ ^ŝŶĞĨƵŶĐƚŝŽŶ
ƚĂŶ dĂŶŐĞŶƚĨƵŶĐƚŝŽŶ
ůŽŐ EĂƚƵƌĂůůŽŐĂƌŝƚŚŵĨƵŶĐƚŝŽŶ;>ŽŐĂƌŝƚŚŵƚŽƚŚĞďĂƐĞĞĨƵŶĐƚŝŽŶͿ
ůŽŐϭϬ >ŽŐĂƌŝƚŚŵƚŽƚŚĞďĂƐĞϭϬĨƵŶĐƚŝŽŶ
ĂĐŽƐ /ŶǀĞƌƐĞŽƐŝŶĞĨƵŶĐƚŝŽŶ
ĂƐŝŶ /ŶǀĞƌƐĞƐŝŶĞĨƵŶĐƚŝŽŶ
ĂƚĂŶ /ŶǀĞƌƐĞƚĂŶŐĞŶƚĨƵŶĐƚŝŽŶ
ZĞĂů ZĞĂůƉĂƌƚŽĨĂĐŽŵƉůĞdžŶƵŵďĞƌ
ŝŵĂŐ /ŵĂŐŝŶĂƌLJƉĂƌƚŽĨĂĐŽŵƉůĞdžŶƵŵďĞƌ
ĂďƐ DĂŐŶŝƚƵĚĞŽĨĂĐŽŵƉůĞdžŶƵŵďĞƌ
ĂŶŐůĞ WŚĂƐĞĂŶŐůĞŽĨĂĐŽŵƉůĞdžŶƵŵďĞƌ
ĐŽŶũ ŽŶũƵŐĂƚĞŽĨĂĐŽŵƉůĞdžŶƵŵďĞƌ
ƌŽƵŶĚ ZŽƵŶĚƚŽƚŚĞŶĞĂƌĞƐƚŝŶƚĞŐĞƌ
ƌĞŵ ZĞŵĂŝŶĚĞƌĂĨƚĞƌĚŝǀŝƐŝŽŶ

,QWURGXFWLRQWR0$7/$% 6
0DNLQJ0DWODE 4XLHW

{ 0$7/$%ZLOOH[HFXWHDQ\
OLQHWKDWHQGVZLWKD

VHPLFRORQ  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I
HOHPHQWV

,QWURGXFWLRQWR0$7/$% 39

{([WUDFWDQ
HOHPHQWRID
PDWUL[

,QWURGXFWLRQWR0$7/$% 40
{([WUDFWDURZ
RIDPDWUL[

,QWURGXFWLRQWR0$7/$% 41

{([WUDFWD
FROXPQRID
PDWUL[

,QWURGXFWLRQWR0$7/$% 42
{$GGDQ
HOHPHQWWRD
PDWUL[

,QWURGXFWLRQWR0$7/$% 43

{$GG
VHTXHQWLDO
HOHPHQWVWRD
PDWUL[

,QWURGXFWLRQWR0$7/$% 44
{5HPRYHD
FROXPQ IURPD
PDWUL[

{5HPRYHDURZ
IURPDPDWUL[

,QWURGXFWLRQWR0$7/$% 45

{([WUDFWWKHODVW
HOHPHQWRIDURZ
IURPDPDWUL[

{([WUDFWWKHODVW
HOHPHQWRIDFROXPQ
IURPDPDWUL[

,QWURGXFWLRQWR0$7/$% 46
{&UHDWH
LGHQWLW\PDWUL[
RU XQLWPDWUL[

,QWURGXFWLRQWR0$7/$% 47

{6FDODU PXOWLSOLFDWLRQ
HOHPHQWE\HOHPHQW

{6FDODUGLYLVLRQ

{6FDODUSRZHU

,QWURGXFWLRQWR0$7/$% 48
7ZRGLPHQVLRQDO3ORW

,QWURGXFWLRQWR0$7/$% 49

7ZRGLPHQVLRQDO3ORW SURSHUWLHV
([DPSOHV
y = 2x3 – 4x2 + 2

,QWURGXFWLRQWR0$7/$% 50
7ZRGLPHQVLRQDO3ORW SURSHUWLHV
plot(independent variable, dependent variable,
3URSHUW\1DPH
)

,QWURGXFWLRQWR0$7/$% 51

7ZRGLPHQVLRQDO3ORW JULGSORWWLQJ
¾ Using: grid
¾ Note: grid command must come after the plot command.
“grid on” or “grid off”

,QWURGXFWLRQWR0$7/$% 52
7ZRGLPHQVLRQDO3ORW D[HVODEHO
¾ X-axis labeling: [ODEHO µQDPH¶
¾ Y-axis labeling: \ODEHO µQDPH¶
¾ Note: labeling commands come after the plot command

,QWURGXFWLRQWR0$7/$%

7ZRGLPHQVLRQDO3ORW D[HVWLWOH
¾ Title of axes: title(‘name’)
¾ Note: title command come after the plot command

,QWURGXFWLRQWR0$7/$% 54
7ZRGLPHQVLRQDO3ORW OHJHQG
¾ Using: legend(‘name’)

,QWURGXFWLRQWR0$7/$% 55

7ZRGLPHQVLRQDO3ORW
SORWWLQJVHYHUDOFXUYHVLQWKHVDPHZLQGRZ
¾ Using: hold on (before plot commands)
¾ Using: hold off (after plot command)

\ VLQ [
] FRV [
W VLQ [ FRV [

,QWURGXFWLRQWR0$7/$% 56
7ZRGLPHQVLRQDO3ORW
SORWWLQJVHYHUDOFXUYHVLQVHSDUDWHGZLQGRZV
¾ Using: figure

,QWURGXFWLRQWR0$7/$% 57

7ZRGLPHQVLRQDO3ORW
SORWWLQJVHYHUDOFXUYHVLQWKUHHVWDFNHGVXESORWV

¾ Using:subplot (before plot


command)
¾ Command: subplot(m,n,p)

,QWURGXFWLRQWR0$7/$% 58
7ZRGLPHQVLRQDO3ORW H[DPSOH 
SORWWLQJVHYHUDOFXUYHVLQWKUHHVWDFNHGVXESORWV

,QWURGXFWLRQWR0$7/$% 59

8VH0$7/$%WRSORW WKHIROORZLQJVLJQDOLQRQHILJXUHDVVKRZQ

,QWURGXFWLRQWR0$7/$%
+RZWRFUHDWHIXQFWLRQ LQ0$7/$%
¾ :LWKRXWSDUDPHWHUV

7KHQDPHRIIXQFWLRQLV
VDPH DVILOH QDPH

džĂŵƉůĞ
&ƵŶĐƚŝŽŶ ĨŝůĞ ZĞĐĂůů ƚŚŝƐ ĨƵŶĐƚŝŽŶ ĨƌŽŵ Ă
ŵĂŝŶƉƌŽŐƌĂŵ;ĂŶŽƚŚĞƌ ĨŝůĞͿ

,QWURGXFWLRQWR0$7/$%

+RZWRFUHDWHIXQFWLRQ LQ0$7/$%

¾ ZLWKSDUDPHWHUV

,QWURGXFWLRQWR0$7/$%

Interesses relacionados