Matlab 第一章习题解答Word文档格式.docx
《Matlab 第一章习题解答Word文档格式.docx》由会员分享,可在线阅读,更多相关《Matlab 第一章习题解答Word文档格式.docx(42页珍藏版)》请在冰豆网上搜索。
![Matlab 第一章习题解答Word文档格式.docx](https://file1.bdocx.com/fileroot1/2023-2/1/aa893770-4b01-4dc9-afec-fc00eb67c713/aa893770-4b01-4dc9-afec-fc00eb67c7131.gif)
Relationaloperators.
eq-Equal==
ne-Notequal~=
lt-Lessthan<
gt-Greaterthan>
le-Lessthanorequal<
=
ge-Greaterthanorequal>
Logicaloperators.
relop-Short-circuitlogicalAND&
&
relop-Short-circuitlogicalOR||
and-Element-wiselogicalAND&
or-Element-wiselogicalOR|
not-LogicalNOT~
xor-LogicalEXCLUSIVEOR
any-Trueifanyelementofvectorisnonzero
all-Trueifallelementsofvectorarenonzero
Specialcharacters.
colon-Colon:
paren-Parenthesesandsubscripting()
paren-Brackets[]
paren-Bracesandsubscripting{}
punct-Functionhandlecreation@
punct-Decimalpoint.
punct-Structurefieldaccess.
punct-Parentdirectory..
punct-Continuation...
punct-Separator,
punct-Semicolon;
punct-Comment%
punct-Invokeoperatingsystemcommand!
punct-Assignment=
punct-Quote'
transpose-Transpose.'
ctranspose-Complexconjugatetranspose'
horzcat-Horizontalconcatenation[,]
vertcat-Verticalconcatenation[;
]
subsasgn-Subscriptedassignment(),{},.
subsref-Subscriptedreference(),{},.
subsindex-Subscriptindex
Bitwiseoperators.
bitand-Bit-wiseAND.
bitcmp-Complementbits.
bitor-Bit-wiseOR.
bitmax-Maximumfloatingpointinteger.
bitxor-Bit-wiseXOR.
bitset-Setbit.
bitget-Getbit.
bitshift-Bit-wiseshift.
Setoperators.
union-Setunion.
unique-Setunique.
intersect-Setintersection.
setdiff-Setdifference.
setxor-Setexclusive-or.
ismember-Trueforsetmember.
Seealsoarith,relop,slash,function_handle.
arith
Arithmeticoperators.
+Plus.
X+YaddsmatricesXandY.XandYmusthavethesame
dimensionsunlessoneisascalar(a1-by-1matrix).
Ascalarcanbeaddedtoanything.
-Minus.
X-YsubtractsmatrixXfromY.XandYmusthavethesame
dimensionsunlessoneisascalar.Ascalarcanbesubtracted
fromanything.
*Matrixmultiplication.
X*YisthematrixproductofXandY.Anyscalar(a1-by-1matrix)
maymultiplyanything.Otherwise,thenumberofcolumnsofXmust
equalthenumberofrowsofY.
.*Arraymultiplication
X.*Ydenoteselement-by-elementmultiplication.XandY
musthavethesamedimensionsunlessoneisascalar.
Ascalarcanbemultipliedintoanything.
^Matrixpower.
Z=X^yisXtotheypowerifyisascalarandXissquare.Ifyisan
integergreaterthanone,thepoweriscomputedbyrepeated
multiplication.Forothervaluesofythecalculation
involveseigenvaluesandeigenvectors.
Z=x^YisxtotheYpower,ifYisasquarematrixandxisascalar,
computedusingeigenvaluesandeigenvectors.
Z=X^Y,wherebothXandYarematrices,isanerror.
.^Arraypower.
Z=X.^Ydenoteselement-by-elementpowers.XandY
musthavethesamedimensionsunlessoneisascalar.
Ascalarcanoperateintoanything.
Relop
Relationaloperators.
<
>
Thesixrelationaloperatorsare<
<
=,>
>
=,==,and~=.
A<
BdoeselementbyelementcomparisonsbetweenAandB
andreturnsamatrixofthesamesizewithelementssettological
1(TRUE)wheretherelationistrueandelementssettological0
(FALSE)whereitisnot.AandBmusthavethesamedimensions
(oronecanbeascalar).
&
Element-wiseLogicalAND.
A&
Bisamatrixwhoseelementsarelogical1(TRUE)wherebothA
andBhavenon-zeroelements,andlogical0(FALSE)whereeitherhas
azeroelement.AandBmusthavethesamedimensions(oronecan
beascalar).
Short-CircuitLogicalAND.
BisascalarvaluethatisthelogicalANDofscalarAandB.
Thisisa"
short-circuit"
operationinthatMATLABevaluatesBonly
iftheresultisnotfullydeterminedbyA.Forexample,ifAequals
0,thentheentireexpressionevaluatestological0(FALSE),regard-
lessofthevalueofB.Underthesecircumstances,thereisnoneed
toevaluateBbecausetheresultisalreadyknown.
|Element-wiseLogicalOR.
A|Bisamatrixwhoseelementsarelogical1(TRUE)whereeither
AorBhasanon-zeroelement,andlogical0(FALSE)wherebothhave
zeroelements.AandBmusthavethesamedimensions(oronecan
||Short-CircuitLogicalOR.
A||BisascalarvaluethatisthelogicalORofscalarAandB.
1,thentheentireexpressionevaluatestological1(TRUE),regard-
lessofthevalueofB.Underthesecircumstances,thereisnoneed
~Logicalcomplement(NOT).
~Aisamatrixwhoseelementsarelogical1(TRUE)whereAhaszero
elements,andlogical0(FALSE)whereAhasnon-zeroelements.
xorExclusiveOR.
xor(A,B)islogical1(TRUE)whereeitherAorB,butnotboth,is
non-zero.SeeXOR.
Slash
Matrixdivision.
\Backslashorleftdivision.
A\BisthematrixdivisionofAintoB,whichisroughlythe
sameasINV(A)*B,exceptitiscomputedinadifferentway.
IfAisanN-by-NmatrixandBisacolumnvectorwithN
components,oramatrixwithseveralsuchcolumns,then
X=A\BisthesolutiontotheequationA*X=Bcomputedby
Gaussianelimination.AwarningmessageisprintedifAis
badlyscaledornearlysingular.A\EYE(SIZE(A))producesthe
inverseofA.
IfAisanM-by-NmatrixwithM<
or>
NandBisacolumn
vectorwithMcomponents,oramatrixwithseveralsuchcolumns,
thenX=A\Bisthesolutionintheleastsquaressensetothe
under-oroverdeterminedsystemofequationsA*X=B.The
effectiverank,K,ofAisdeterminedfromtheQRdecomposition
withpivoting.AsolutionXiscomputedwhichhasatmostK
nonzerocomponentspercolumn.IfK<
Nthiswillusuallynot
bethesamesolutionasPINV(A)*B.A\EYE(SIZE(A))producesa
generalizedinverseofA.
/Slashorrightdivision.
B/AisthematrixdivisionofAintoB,whichisroughlythe
sameasB*INV(A),exceptitiscomputedinadifferentway.
Moreprecisely,B/A=(A'
\B'
)'
.See\.
./Arrayrightdivision.
B./Adenoteselement-by-elementdivision.AandB
Ascalarcanbedividedwithanything.
.\Arrayleftdivision.
A.\B.denoteselement-by-elementdivision.AandB
function_
FUNHANDLE=@FUNCTION_NAMEreturnsahandletothenamedfunction,
FUNCTION_NAME.AfunctionhandleisaMATLABvaluethatprovidesa
meansofcallingafunctionindirectly.Youcanpassfunction
handlesincallstootherfunctions(whichareoftencalledfunction
functions).Youcanalsostorefunctionhandlesindatastructuresfor
lateruse(forexample,asHandleGraphicscallbacks).Afunction
handleisoneofthestandardMATLABdatatypes.Itsclassis
'
function_handle'
.
FUNHANDLE=@(ARGLIST)EXPRESSIONconstructsananonymousfunctionand
returnsahandletothatfunction.Thebodyofthefunction,tothe
rightoftheparentheses,i