变换规则和定义

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

第9讲变换规则和定义1.应用变换规则2.对规则的操作3.定义4.赋值的一些特殊形式5.索引的定义6.函数的定义7.定义的次序8.即时和延时的定义9.记住已知值的函数10.定义联系不同的符号11.定义数值值12.修改内置函数13.使用赋值列表TOP2November18,2004StartLearningStepbyStep1.应用变换规则expr/.rules在表达式上应用一次规则expr//.rules在表达式上重复应用规则直道结果不再改变应用变换规则expr/.lhs-rhs在表达式上应用某个变换规则expr/.{lhs1-rhs1,lhs2-rhs,...}在表达式上依次应用一系列规则应用一组变换规则expr/.{rules1,rules2,...}应用一组规则得到一个数组一次或重复应用规则TOP3November18,2004StartLearningStepbyStep1.应用变换规则(续)Applyingrulestowholeexpressionsexpr/.rulesapplyrulestoallsubpartsofexprReplace[expr,rules]applyrulestothewholeofexpronlyReplace[expr,rules,levspec]applyrulestopartsofexpronlevelsspecifiedbylevspecApplyingrulesinonewayorallpossiblewaysReplace[expr,rules]applyrulesinonewayonlyReplaceList[expr,rules]applyrulesinallpossiblewaysTOP4November18,2004StartLearningStepbyStep2.对规则的操作CreatingandusingdispatchtablesDispatch[rules]createarepresentationofalistofrulesthatincludesdispatchtablesexpr/.drulesapplyrulesthatincludedispatchtablesTOP5November18,2004StartLearningStepbyStep3.定义Manualandautomaticapplicationoftransformationrulesexpr/.lhs-rhsapplyatransformationruletoaspecificexpressionlhs=rhsassignavaluewhichdefinesatransformationruletobeusedwheneverpossibleRemovingassignmentsx=.removethevalueassignedtotheobjectxClear[x,y,...]clearallthevaluesofx,y,...TOP6November18,2004StartLearningStepbyStep4.赋值的一些特殊形式Modifyingvaluesofvariablesi++incrementthevalueofiby1i--decrementi++ipre-incrementi--ipre-decrementii+=diaddditothevalueofii-=disubtractdifromix*=cmultiplyxbycx/=cdividexbycTOP7November18,2004StartLearningStepbyStep4.赋值的一些特殊形式(续)Assigningvaluestoseveralvariablesatatimex=y=valueassignthesamevaluetobothxandy{x,y}={value1,value2}assigndifferentvaluestoxandy{x,y}={y,x}interchangethevaluesofxandyAssignmentsformodifyinglistsPrependTo[v,elem]prependelemtothevalueofvAppendTo[v,elem]appendelemv={v,elem}makeanestedlistcontaningelemTOP8November18,2004StartLearningStepbyStep5.索引的定义Manipulatingindexedvariablesa[i]=valueaddoroverwriteavaluea[i]accessavaluea[i]=.removeavalue?ashowalldefinedvaluesClear[a]clearalldefinedvaluesTable[a[i],{i,1,n}]orArray[a,n]converttoanexplicitListTOP9November18,2004StartLearningStepbyStep6.函数的定义f[x]=valuedefinitionforaspecificexpressionxf[x_]=valuedefinitionforanyexpression,referredtoasxThedifferencebetweendefininganindexedvariableandafunctionTOP10November18,2004StartLearningStepbyStep7.定义的次序TreatmentofdefinitionsinMathematicaMathematicatriestoputspecificdefinitionsbeforemoregeneraldefinitionsTOP11November18,2004StartLearningStepbyStep8.即时和延时的定义lhs=rhs(immediateassignment)rhsisevaluatedwhentheassignmentismadelhs:=rhs(delayedassignment)rhsisevaluatedeachtimethevalueoflhsisrequestedThetwotypesofassignmentsinMathematicaInterpretationsofassignmentswiththe=and:=operatorslhs=rhsrhsisintendedtobethefinalvalueoflhs(e.g.,f[x_]=1-x^2)lhs:=rhsrhsgivesacommandorprogramtobeexecutedwheneveryouaskforthevalueoflhs(e.g.,f[x_]:=Expand[1-x^2])Definingfunctionsforevaluatingexpressionsf[x_]=exprdefineafunctionwhichgivesthevalueexprforanyparticularvalueofxTOP12November18,2004StartLearningStepbyStep8.即时和延时的定义(续)lhs-rhsrhsisevaluatedwhentheruleisgivenlhs:rhsrhsisevaluatedwhentheruleisusedTwotypesoftransformationrulesinMathematicaTOP13November18,2004StartLearningStepbyStep9.记住已知值的函数f[x_]:=f[x]=rhsdefineafunctionwhichremembersvaluesthatitfindsDefiningafunctionthatremembersvaluesitfindsTOP14November18,2004StartLearningStepbyStep10.定义联系不同的符号Associatingdefinitionswithdifferentsymbolsf[args]:=rhsdefineadownvalueforff[g[args],...]^:=rhsdefineanupvalueforgShorterwaystodefineupvaluesf[g]^=valueorf[g[args]]^=valuemakeassignmentstobeassociatedwithg,ratherthanff[g]^:=valueorf[g[args]]^:=valuemakedelayedassignmentsassociatedwithgf[arg1,arg2,...]^=valuemakeassignmentsassociatedwiththeheadsofalltheargiTOP15November18,2004StartLearningStepbyStep10.定义联系不同的符号(续)Possiblepositionsforsymbolsindefinitionsf[...]:=rhsdownvalueforff/:f[g[...]][...]:=rhsdownvalueforfg/:f[...,g,...]:=rhsupvalueforgg/:f[...,g[...],...]:=rhsupvalueforgTOP16November18,2004StartLearningStepbyStep11.定义数值值Definingordinaryandnumericalvaluesexpr=valuedefineavaluetobeusedwheneverpossibleN[expr]=valuedefineavaluetobeusedfornumericalapproximationDefiningnumericalvaluesthatdependonnumericalprecisionN[expr]=valuedefineanumericalvaluetobeusedwhendefalutnumericalprecisionisrequestedN[expr,n]=valuedefineanumericalvaluetobeusedwhenn-digitprecisionisrequestedTOP17November18,2004StartLearningStepbyStep12.修改内置函数ProtectionforfunctionsUnprotect[f]removeprotectionProtect[f]addprotectionTOP18November18,2004StartLearningStepbyStep13.使用赋值列表FindingandsettingvaluesofsymbolsDownValues[f]givethelistofdownvaluesoffUpValues[f]givethelistofupvaluesoffDownValues[f]=rulessetthedownvaluesoffUpValues[f]=rulessettheupvaluesoff

1 / 18
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功