Template:複變運算/doc

来自testwiki
跳转到导航 跳转到搜索

Template:NoteTA Template:Other usesTemplate:Documentation subpageTemplate:High-use Template:LuaTemplate:模板樣式 Template:Tl模板為Help:计算功能的一個擴展,提供了一些Help:计算不支援的計算。

概要

本模板比Help:计算多了以下功能:

使用方法

本模板的第一參數為欲計算的運算式,關於運算式的語法詳見#語法一節。參數number class為指定運算時使用的數體。若使用其軟重定向版本Template:Tl則有第二參數可以使用,用途為指定輸出的小數位數。

其基礎語法為: Template:SquoteTemplate:Squote

參數說明

語法

本節將說明本模板輸入的運算式之語法。

項目 語法 說明 範例
數字的表達
實數
Template:Background colorTemplate:Background color
科學記號
Template:Nowrap
含單位的數
Template:Background colorTemplate:Background colorTemplate:Background color
含常數單位
Template:Nowrap
數字的表達可分為實數表達、科學記號和含單位的數。
  • 實數表達即一般的實數;
  • 科學記號為一實數緊接著一個Template:Nowrap和一個整數,例如Template:Nowrap則代表Template:Nowrap
  • 另一個表達方式為一個實數值緊接著一個複變單位或角度單位,例如2i表示兩倍的虛數單位。此表達式不能與科學記號一同使用。能使用的單位包括ijk°π。其餘需使用Template:Nowrap運算子來表達。
Template:XpettTemplate:XpettbTemplate:XpettbTemplate:Xpett
Template:Nowrap 3.14159...
Template:Nowrap 6.28318...
Template:Nowrap 5.43656...
Template:Nowrap hideText|Template:複變運算}}Template:Error
四則運算與冪運算 Template:Background colorTemplate:0Template:Background colorTemplate:0Template:Background color 依序以中綴表示法表達運算式即可。 Template:XpettTemplate:XpettuTemplate:Xpettb
Template:Background colorTemplate:0(Template:0Template:Background color,Template:0Template:Background colorTemplate:0...) 调用现有函数。所有函數都至少要傳入一個參數。 Template:XpettTemplate:XpettTemplate:Xpett
多組運算 Template:Background colorTemplate:0Template:Background colorTemplate:0Template:Background color 僅會顯示最後一組運算的結果 Template:XpettbTemplate:XpettbTemplate:Xpettb
變數定義 Template:Background colorTemplate:0Template:Background colorTemplate:0Template:Background color 給特定名稱的變數賦值。需特別注意所有變數的範圍(Scope)皆相同(可想像所有變數皆為全域變數),包括函數中的參數,因此若函數外層已經定義了變數x則函數內部需避免使用同名變數x。 Template:XpettTemplate:XpettuTemplate:Xpettb
Template:Nowrap Template:Nowrap 數的語法為以名稱起始並以冒號區隔函數名稱與定義(函數名稱可留空,但冒號不能省去),整個語法要以Template:Nowrap結尾。位於Template:Nowrap前方為函數的變數或參數,後方為函數主體定義,即Template:Nowrap。函數可以有多個變數,但僅能有單個輸出,即nn。同時函數語法不建議寫成嵌套結構,即不建議將函數定義內包含另一個函數的定義,但可以分開定義Template:AnyLink;此外,函數定義內不能包含分號,因為分號會視為函數的結尾。 Template:XpettbTemplate:Xpettu
Template:Nowrap f(5)}} Template:計算
運算符優先序調整 (Template:Background colorTemplate:0Template:Background colorTemplate:0Template:Background color)Template:0Template:Background colorTemplate:0Template:Background color 使用括號來令特定運算優先進行。

Template:HideH Template:複變運算/語法 Template:HideF

自訂函數用法

具名函數

基本函數定義方式為「Template:Math」。

例如若要表達f(x)=x2,則其應寫為「Template:Math

匿名函數

匿名函數的語法為「Template:Nowrap

以上例x2而言,對應的匿名函數應寫為「Template:Math

匿名函數可以被直接呼叫,例如「Template:Tlx」→「Template:計算結果

函數中的函數

函數中可以包含另一個函數,例如「Template:Tlx」→「Template:計算結果

函數作為參數
部分函數是以函數作為參數,例如summation(Template:0)product(Template:0)和一些微積分函數。條件運算式(if(Template:0))也有函數呼叫的版本iff(Template:0)
  • 求和、求積與微積分函-{}-數
    求和函-{}-數(summation(start,end,function)i=startendfunction)、求積函-{}-數(summation(start,end,function)i=startendfunction)、微分(diff(function,x0)dfunctiondx|x=x0)、積分(integral(a,b,function)abfunctiondx)、極限(limit(x0,way,function)limxx0wayfunction)皆須傳入一個匿名函數,作為其數列計算的依據。
    以求和函-{}-數summation(start,end,function)為例,若要表達x2x從1到5的和,則代碼為:
    Template:Tlx」→「Template:計算結果
    • 求和/求積函-{}-數的變數
      一般求和/求積函-{}-數的變數通常是i、j或k,而在此運算系統中,i、j與k已被視作常數無法使用。若需要讓顯示出來的結果為i、j或k可在英文字母後方加「t」,如it、jt或kt,顯示時t會省去:
    Template:Tlx」→「Template:計算結果
  • 函數條件運算式(iff(條件,為真,為假)
    條件運算式除了給定條件外,其為真的結果與為假的結果要是一個無參數的匿名函數。無參數的匿名函數定義方式為「Template:Nowrap
    例如「Template:Tlx」→「Template:計算結果
    例如「Template:Tlx」→「Template:計算結果
函數的遞迴
具名函數可以遞迴調用,但須注意遞迴需要消耗較多的效能。函數的遞迴需要給出初始條件與遞迴結果,因此需要使用條件運算式,若用if(Template:0)會導致無窮呼叫而發生錯誤,因此需要使用到iff(Template:0)

範例

限制

本模板僅支援輸入數字(0-9)、已定義的運算子符號({{#invoke:Complex Number/Calculate/doc.lua|allOperator|comma=、 |pattern=%s}})和半角英文字母(a-z及A-Z),其餘字元都會被忽略。

參數

Template:TemplateDataHeader <templatedata> { "params": { "1": { "label": "運算式", "description": "要計算的運算式", "type": "string", "required": true }, "2": { "label": "小數位數 (計算模板專用)", "description": "使用Template:計算模板時才支持這個參數。", "type": "number" }, "number class": { "label": "運算數字模式", "description": "要運算的數字模式,可以是實數、cmath(複數)、qmath(四元數)、no calc(不計算)、mathtag(以<math>輸出)或直接寫Module:模組名稱.運算庫來指定使用特定模組來運算。", "type": "string", "default": "cmath", "suggestedvalues": [ "real", "cmath", "qmath", "no calc", "mathtag", "實數", "複數", "四元數" ] }, "use math": { "label": "使用<math>", "description": "是否使用<math>", "type": "boolean", "default": "no" }, "should math": { "label": "是否以<math>原碼輸出", "description": "輸出結果字串是否轉換為<math>原碼格式輸出。若use math設定為是,則此參數會自動當成是。", "type": "boolean", "default": "no" }, "useOtherModule": { "label": "是否可呼叫其他模組", "description": "是否可呼叫其他模組的函數。", "type": "boolean", "default": "no" } }, "format": "inline", "description": "進行複變數的運算" } </templatedata>

重定向

參見