playground:playground

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
playground:playground [2021/09/27 13:26]
jojo1973
playground:playground [2021/10/01 09:08]
jojo1973 removed
Line 1: Line 1:
-==== Numerical integration ====+===== Numerical integration =====
  
-Numeric integration of symbolic expressions is implemented in **newRPL** via the ''[[manual:chapter6:solvers:cmd_numint|NUMINT]]'' command which implements the [[https://en.wikipedia.org/wiki/Adaptive_Simpson%27s_method|Adaptive Simpson's method]].+Numeric integration of symbolic expressions is performed in **newRPL** via the ''[[manual:chapter6:solvers:cmd_numint|NUMINT]]'' command which implements the [[https://en.wikipedia.org/wiki/Adaptive_Simpson%27s_method|Adaptive Simpson's method]].
  
 ''[[manual:chapter6:solvers:cmd_numint|NUMINT]]'' accepts four arguments: ''[[manual:chapter6:solvers:cmd_numint|NUMINT]]'' accepts four arguments:
Line 17: Line 17:
  
 For example valid expressions are: For example valid expressions are:
 +
 <code> <code>
-F(X)=X*LN(X) +'F(X)=X*LN(X)' 
-G(Z)=Z^2-2*COS(Z) +'G(Z)=Z^2-2*COS(Z)' 
-VEL(T)=ACC*T+'VEL(T)=ACC*T'
 </code> </code>
 +
 As shown above, the functions may refer to global or local variables; the function's name is only descriptive and bears no relevance to the calculation. As shown above, the functions may refer to global or local variables; the function's name is only descriptive and bears no relevance to the calculation.
  
Line 37: Line 39:
 ---- ----
  
-=== Examples ===+==== Angles and trigonometric expressions ====
  
-The following examples are calculated with 16 precision digits using three different tolerancesIf available, the analytic result is provided for comparison.+When a real number is input to a trigonometric function **newRPL** assumes that it is an angle expressed in the current angular mode; however the trigonometric functions are meant to process quantities expressed in radians. In other words the following transformations are implicitly applied: 
 + 
 +  * in ''[[manual:chapter6:flags:cmd_rad|RAD]]'' mode $ θ=θ_{r}\, $; 
 +  * in ''[[manual:chapter6:flags:cmd_deg|DEG]]'' mode $ θ=\frac{\pi}{180}{θ_°}\, $; 
 +  * in ''[[manual:chapter6:flags:cmd_grad|GRAD]]'' mode $ θ=\frac{\pi}{200}{θ_g}\, $. 
 + 
 +where $θ_{r}\,$, $θ_{°}$ and $θ_{g}$ are the quantities entered by the user and $θ$ is what is actually fed to the trigonometric functions. 
 + 
 +From this, two important consequences derive: 
 + 
 +  - the antiderivative changes according to the angular mode. Let's consider e.g. the function $ f(θ)=\sin{θ} $ and apply the transformations above:\\ \\ 
 +    * in ''[[manual:chapter6:flags:cmd_rad|RAD]]'' mode $ f(θ_r) $ is equivalent to $ f(θ) $ which differentiates to $ f(θ_r)\,dθ_r=\sin{θ}\,d{θ} $ and whose antiderivative is $ F(θ)=-\cos{θ}\, $; 
 +    * in ''[[manual:chapter6:flags:cmd_deg|DEG]]'' mode $ f(θ_°) $ is actually $ f\left(\frac{\pi}{180}θ_°\right) $ which differentiates to $ f\left(\frac{\pi}{180}θ_°\right)\,dθ_°=\frac{180}{\pi}\sin{θ}\,d{θ} $ and whose antiderivative is $ F(θ)=-\frac{180}{\pi}\cos{θ}\, $; 
 +    * in ''[[manual:chapter6:flags:cmd_grad|GRAD]]'' mode $ f(θ_g) $ is actually $ f\left(\frac{\pi}{200}θ_g\right) $ which differentiates to $ f\left(\frac{\pi}{200}θ_g\right)\,dθ_g=\frac{200}{\pi}\sin{θ}\,d{θ} $ and whose antiderivative is $ F(θ)=-\frac{200}{\pi}\cos{θ}\, $;\\ \\ 
 +  - no inverse transformation is applied to the resulting output: this is mathematically correct, but can be disconcerting if one is not immediately aware of the implicit variable substitution. 
 +\\ 
 +In conclusion, unless the user knows exactly what he/she is doing it's advisable **to perform numeric integration of trigonometric expressions in ''[[manual:chapter6:flags:cmd_rad|RAD]]'' mode**. 
 + 
 +---- 
 + 
 +==== Example 1: Bound function on closed interval ==== 
 + 
 +|  pic  |  $$ \int^{2}_{0} x^{10}e^{\left(4x^{3}-3x^{4}\right)} \,dx $$  | **Input:**\\ <code>16 SETPREC 
 +'F(X)=X^10*EXP(4*X^3-3*X^4)' 
 +
 +
 +tol 
 +NUMINT</code>  || 
 +|  :::  |  tol=10<sup>-4</sup>   | **7.258 3**76 114 514 225 ...  |  Δ = -1.9·10<sup>-5</sup> 
 +|  :::  |  tol=10<sup>-8</sup>   | **7.258 395 17**3 115 920 ...  |  Δ = 2.5·10<sup>-9</sup> 
 +|  :::  |  tol=10<sup>-12</sup>  | **7.258 395 170 61**5 141 ...  |  Δ = 8.5·10<sup>-13</sup> 
 +|  :::  |  Exact at the precision shown  | **[[https://www.wolframalpha.com/input/?i=integrate+x%5E10*exp%284*x%5E3-3*x%5E4%29+from+0+to+2+to+16+digits|7.258 395 170 614 291]]** ...  |   Δ ≤ 10<sup>-16</sup> 
 + 
 +---- 
 + 
 +==== Example 2: XXX ==== 
 + 
 +---- 
 + 
 +==== Example 3: XXX ==== 
 + 
 +----
  
-^  Function  ^  Tolerance  ^^^  Exact Solution  ^^ +==== Example 4: XXX ====
-^    ^  ''1E-4''  ^  ''1E-8''  ^  ''1E-12''  ^    ^ +
-| $ \int^{5/4}_{0} \cos x^2 \,dx $  |  0.977 4  |  0.977 437 67  |  0.977 437 670 720  |  $ \sqrt\frac{\pi}{2} C\left(\sqrt\frac{2}{\pi} x\right) \Biggr|^{x=5/4}_{x=0} $  |  0.977 437 670 720 3...  | +
-| $ \int^{2}_{0} e^{-2x}\left(14x-11x^{2}\right) \,dx $  |  1.084 2  |  1.084 260 41  |  1.084 260 409 719  |  $  \frac{3}{4}+\frac{73}{4e^{4}} $  |  1.084 260 409 719 3...  | +
-| $ \int^{2}_{0} x^{10}e^{\left(4x^{3}-3x^{4}\right)} \,dx $  |  7.258 4  |  7.258 395 17  |  7.258 395 170 615  |  No analytic solution exists  |  7.258 395 170 614 3...  |+
  
-|{{:manual:warning-145066_640.png?100 |Warning!}} The user must take care of implicit substitutions when the expression to integrate __contains trigonometric functions__. For example, if the angle mode is set to degrees, the expression $ \sin x $ is actually interpreted as $ \sin\left(\frac{\pi}{180}x\right) $, whose anti-derivative is **not** $-\cos x$, but $-\frac{180}{\pi}\cos\left(\frac{\pi}{180}x\right) $. Unexpected results will follow if the user disregards this occurrence! | 
  • playground/playground.txt
  • Last modified: 2021/10/11 13:50
  • by jojo1973