Files
rappaurio-sae501_502/app/node_modules/cejs/_documents/JsDoc/symbols/src/D__USB_cgi-bin_lib_JS_data_math_polynomial.origin.js.html
2023-09-25 13:27:24 +02:00

199 lines
48 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <style>
.KEYW {color: #933;}
.COMM {color: #bbb; font-style: italic;}
.NUMB {color: #393;}
.STRN {color: #393;}
.REGX {color: #339;}
.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
</style></head><body><pre><span class='line'> 1</span> <span class="TOKN"></span><span class="WHIT">
<span class='line'> 2</span> </span><span class="COMM">/**
<span class='line'> 3</span> * @name CeL polynomial function
<span class='line'> 4</span> * @fileoverview
<span class='line'> 5</span> * 本檔案包含了數學多項式的 functions。
<span class='line'> 6</span> * @since
<span class='line'> 7</span> */</span><span class="WHIT">
<span class='line'> 8</span>
<span class='line'> 9</span>
<span class='line'> 10</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">CeL</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 11</span> </span><span class="NAME">CeL.setup_module</span><span class="PUNC">(</span><span class="STRN">'data.math.polynomial'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">library_namespace</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">load_arguments</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 13</span>
<span class='line'> 14</span> </span><span class="COMM">// no required</span><span class="WHIT">
<span class='line'> 15</span>
<span class='line'> 16</span>
<span class='line'> 17</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 18</span> </span><span class="COMM">/**
<span class='line'> 19</span> * null module constructor
<span class='line'> 20</span> * @class 數學多項式相關之 function。
<span class='line'> 21</span> * @constructor
<span class='line'> 22</span> */</span><span class="WHIT">
<span class='line'> 23</span> </span><span class="NAME">CeL.data.math.polynomial</span><span class="WHIT">
<span class='line'> 24</span> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 25</span> </span><span class="WHIT"> </span><span class="COMM">// null module constructor</span><span class="WHIT">
<span class='line'> 26</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 27</span>
<span class='line'> 28</span> </span><span class="COMM">/**
<span class='line'> 29</span> * for JSDT: 有 prototype 才會將之當作 Class
<span class='line'> 30</span> */</span><span class="WHIT">
<span class='line'> 31</span> </span><span class="NAME">CeL.data.math.polynomial</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="PUNC">.</span><span class="NAME">prototype</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 33</span>
<span class='line'> 34</span>
<span class='line'> 35</span>
<span class='line'> 36</span>
<span class='line'> 37</span>
<span class='line'> 38</span> </span><span class="COMM">// polynomial -----------------------------------</span><span class="WHIT">
<span class='line'> 39</span>
<span class='line'> 40</span> </span><span class="COMM">/*
<span class='line'> 41</span> return [r1,r2,..[,餘式]]
<span class='line'> 42</span> ** 若有無法解的餘式,會附加在最後!
<span class='line'> 43</span>
<span class='line'> 44</span> 高次代數方程數值求根解法: http://www.journals.zju.edu.cn/sci/2003/200303/030305.pdf http://tsg.gxtvu.com.cn/eduwest/web_courseware/maths/0092/2/2-3.htm
<span class='line'> 45</span> 修正牛頓法 1819年霍納法 伯努利法 勞思表格法 http://en.wikipedia.org/wiki/Ruffini%27s_rule
<span class='line'> 46</span> Newton's method牛頓法 x2=x1-f(x1)/f'(x1) http://zh.wikipedia.org/wiki/%E7%89%9B%E9%A1%BF%E6%B3%95
<span class='line'> 47</span> 四次方程Finding roots http://zh.wikipedia.org/wiki/%E5%9B%9B%E6%AC%A1%E6%96%B9%E7%A8%8B
<span class='line'> 48</span> 一元三次方程的公式解 http://en.wikipedia.org/wiki/Cubic_equation http://math.xmu.edu.cn/jszg/ynLin/JX/jiaoxueKJ/5.ppt
<span class='line'> 49</span>
<span class='line'> 50</span> var rootFindingFragment=1e-15; // 因為浮點乘除法而會產生的誤差
<span class='line'> 51</span> */</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="NAME">rootFinding</span><span class="PUNC">[</span><span class="NAME">generateCode.dLK</span><span class="PUNC">]</span><span class="PUNC">=</span><span class="STRN">'rootFindingFragment'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">rootFinding</span><span class="PUNC">(</span><span class="NAME">polynomial</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">r</span><span class="PUNC">=</span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">a</span><span class="PUNC">,</span><span class="NAME">q</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 55</span>
<span class='line'> 56</span> </span><span class="WHIT"> </span><span class="COMM">//alert(NewtonMethod(polynomial));</span><span class="WHIT">
<span class='line'> 57</span>
<span class='line'> 58</span> </span><span class="WHIT"> </span><span class="KEYW">while</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">polynomial.length</span><span class="PUNC">,</span><span class="NAME">a</span><span class="PUNC">></span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">&lt;</span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">==</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="NAME">r.push</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">/</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">*</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">-</span><span class="NUMB">4</span><span class="PUNC">*</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">*</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// b^2-4ac</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT"> </span><span class="NAME">q</span><span class="PUNC">=</span><span class="NUMB">2</span><span class="PUNC">*</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">&lt;</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="NAME">a</span><span class="PUNC">=</span><span class="PUNC">(</span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NAME">a</span><span class="PUNC">)</span><span class="PUNC">/</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">+</span><span class="STRN">'i'</span><span class="PUNC">,</span><span class="NAME">q</span><span class="PUNC">=</span><span class="PUNC">-</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">/</span><span class="NAME">q</span><span class="PUNC">,</span><span class="NAME">r.push</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">+</span><span class="STRN">'+'</span><span class="PUNC">+</span><span class="NAME">a</span><span class="PUNC">,</span><span class="NAME">q</span><span class="PUNC">+</span><span class="STRN">'-'</span><span class="PUNC">+</span><span class="NAME">a</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">)</span><span class="PUNC">/</span><span class="NAME">q</span><span class="PUNC">,</span><span class="NAME">q</span><span class="PUNC">=</span><span class="PUNC">-</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">/</span><span class="NAME">q</span><span class="PUNC">,</span><span class="NAME">r.push</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">+</span><span class="NAME">a</span><span class="PUNC">,</span><span class="NAME">q</span><span class="PUNC">-</span><span class="NAME">a</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT"> </span><span class="NAME">polynomial</span><span class="PUNC">=</span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">NewtonMethod</span><span class="PUNC">(</span><span class="NAME">polynomial</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">></span><span class="NAME">rootFindingFragment</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT"> </span><span class="COMM">//alert('rootFinding: NewtonMethod 無法得出根!\n誤差:'+a[1]);</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT"> </span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">qNum</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NUMB">1</span><span class="NAME">e6</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="COMM">//alert(a[0]+'/'+a[1]);</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT"> </span><span class="NAME">q</span><span class="PUNC">=</span><span class="NAME">pLongDivision</span><span class="PUNC">(</span><span class="NAME">polynomial</span><span class="PUNC">,</span><span class="PUNC">[</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="PUNC">-</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">></span><span class="NAME">pLongDivisionFragment</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="NAME">alert</span><span class="PUNC">(</span><span class="STRN">'rootFinding error!\n誤差:'</span><span class="PUNC">+</span><span class="NAME">q</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="KEYW">break</span><span class="PUNC">;</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT"> </span><span class="NAME">r.push</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">/</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">polynomial</span><span class="PUNC">=</span><span class="NAME">q</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT"> </span><span class="COMM">//alert('get root: '+a[0]+'\n'+polynomial);</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 78</span>
<span class='line'> 79</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">polynomial.length</span><span class="PUNC">==</span><span class="NUMB">5</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT"> </span><span class="COMM">// 兩對共軛虛根四次方程</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT"> </span><span class="NAME">q</span><span class="PUNC">=</span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">polynomial.length</span><span class="PUNC">,</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT"> </span><span class="KEYW">while</span><span class="PUNC">(</span><span class="PUNC">--</span><span class="NAME">a</span><span class="PUNC">)</span><span class="NAME">q.push</span><span class="PUNC">(</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">]</span><span class="PUNC">*</span><span class="NAME">a</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// 微分</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">=</span><span class="NAME">rootFinding</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">q.length</span><span class="PUNC">></span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT"> </span><span class="COMM">//a=0;for(var i=0;i&lt;polynomial.length;i++)a=a*q[0]+polynomial[i];</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT"> </span><span class="COMM">// 將函數上下移動至原極值有根處,則會有二重根。原函數之根應為(-b +- (b^2-4ac)^.5)/2a則此二重根即為-b/2a</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT"> </span><span class="COMM">// 故可將原函數分解為(x^2-2*q[n]*x+&)(?x^2+?x+?)</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT"> </span><span class="COMM">// 以長除法解之可得&有三解:a*&^2+(-2*q[n]*(b+2*a*q[n])-c)*&+e=0 or ..</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT"> </span><span class="NAME">q</span><span class="PUNC">=</span><span class="NAME">q</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">a</span><span class="PUNC">=</span><span class="NUMB">4</span><span class="PUNC">*</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">*</span><span class="NAME">q</span><span class="PUNC">+</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">==</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">rootFinding</span><span class="PUNC">(</span><span class="PUNC">[</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">*</span><span class="NAME">q</span><span class="PUNC">*</span><span class="PUNC">(</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">+</span><span class="NUMB">2</span><span class="PUNC">*</span><span class="NAME">q</span><span class="PUNC">*</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">-</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">4</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">a.length</span><span class="PUNC">&lt;</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="NAME">a</span><span class="PUNC">=</span><span class="KEYW">null</span><span class="PUNC">;</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">=</span><span class="PUNC">(</span><span class="NUMB">2</span><span class="PUNC">*</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="PUNC">*</span><span class="NAME">q</span><span class="PUNC">+</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">3</span><span class="PUNC">]</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">*</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">*</span><span class="NAME">q</span><span class="PUNC">*</span><span class="PUNC">(</span><span class="NUMB">2</span><span class="PUNC">*</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">*</span><span class="NAME">q</span><span class="PUNC">+</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">/</span><span class="NAME">a</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">o</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">isNaN</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">)</span><span class="PUNC">&&</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">=</span><span class="NAME">pLongDivision</span><span class="PUNC">(</span><span class="NAME">polynomial</span><span class="PUNC">,</span><span class="NAME">o</span><span class="PUNC">=</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">*</span><span class="NAME">q</span><span class="PUNC">,</span><span class="NAME">a</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">&lt;</span><span class="NAME">pLongDivisionFragment</span><span class="PUNC">&&</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">&lt;</span><span class="NAME">pLongDivisionFragment</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">rootFinding</span><span class="PUNC">(</span><span class="NAME">q</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">r.push</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">a</span><span class="PUNC">=</span><span class="NAME">rootFinding</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">r.push</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">polynomial</span><span class="PUNC">=</span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 95</span>
<span class='line'> 96</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">polynomial.length</span><span class="PUNC">></span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="WHIT"> </span><span class="NAME">r.push</span><span class="PUNC">(</span><span class="NAME">polynomial</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 98</span> </span><span class="WHIT"> </span><span class="COMM">//if(polynomial.length%2==1)alert('rootFinding error!');</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">r</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>101</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>102</span> </span><span class="COMM">//alert(rootFinding(getPbyR([1,4/3,5,2,6])).join('\n'));</span><span class="WHIT">
<span class='line'>103</span> </span><span class="COMM">//alert(NewtonMethod(getPbyR([1,4,5,2,6])).join('\n'));</span><span class="WHIT">
<span class='line'>104</span> </span><span class="COMM">//alert(rootFinding([1,4,11,14,10]).join('\n'));</span><span class="WHIT">
<span class='line'>105</span> </span><span class="COMM">//alert(rootFinding([1,2,3,2,1]).join('\n'));</span><span class="WHIT">
<span class='line'>106</span>
<span class='line'>107</span> </span><span class="COMM">/* 長除法 polynomial long division http://en.wikipedia.org/wiki/Polynomial_long_division 2005/3/4 18:48
<span class='line'>108</span> dividend/divisor=quotient..remainder
<span class='line'>109</span>
<span class='line'>110</span> input (dividend,divisor)
<span class='line'>111</span> return [商,餘式]
<span class='line'>112</span>
<span class='line'>113</span> var pLongDivisionFragment=1e-13; // 因為浮點乘除法而會產生的誤差
<span class='line'>114</span> */</span><span class="WHIT">
<span class='line'>115</span> </span><span class="NAME">pLongDivision</span><span class="PUNC">[</span><span class="NAME">generateCode.dLK</span><span class="PUNC">]</span><span class="PUNC">=</span><span class="STRN">'pLongDivisionFragment'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>116</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">pLongDivision</span><span class="PUNC">(</span><span class="NAME">dividend</span><span class="PUNC">,</span><span class="NAME">divisor</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">dividend</span><span class="PUNC">!=</span><span class="STRN">'object'</span><span class="PUNC">||</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">divisor</span><span class="PUNC">!=</span><span class="STRN">'object'</span><span class="PUNC">)</span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT"> </span><span class="KEYW">while</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dividend</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="NAME">dividend.shift</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="KEYW">while</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">divisor</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="NAME">dividend.shift</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dividend.length</span><span class="PUNC">||</span><span class="PUNC">!</span><span class="NAME">divisor.length</span><span class="PUNC">)</span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>120</span>
<span class='line'>121</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">quotient</span><span class="PUNC">=</span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">remainder</span><span class="PUNC">=</span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">r</span><span class="PUNC">,</span><span class="NAME">r0</span><span class="PUNC">=</span><span class="NAME">divisor</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">c</span><span class="PUNC">=</span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="NAME">l2</span><span class="PUNC">=</span><span class="NAME">divisor.length</span><span class="PUNC">,</span><span class="NAME">l</span><span class="PUNC">=</span><span class="NAME">dividend.length</span><span class="PUNC">-</span><span class="NAME">l2</span><span class="PUNC">+</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="NAME">i</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>122</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="NAME">dividend.length</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="NAME">remainder.push</span><span class="PUNC">(</span><span class="NAME">dividend</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT"> </span><span class="KEYW">while</span><span class="PUNC">(</span><span class="PUNC">++</span><span class="NAME">c</span><span class="PUNC">&lt;</span><span class="NAME">l</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">quotient.push</span><span class="PUNC">(</span><span class="NAME">r</span><span class="PUNC">=</span><span class="NAME">remainder</span><span class="PUNC">[</span><span class="NAME">c</span><span class="PUNC">]</span><span class="PUNC">/</span><span class="NAME">r0</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">1</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="NAME">l2</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>125</span> </span><span class="WHIT"> </span><span class="NAME">remainder</span><span class="PUNC">[</span><span class="NAME">c</span><span class="PUNC">+</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">-</span><span class="PUNC">=</span><span class="NAME">r</span><span class="PUNC">*</span><span class="NAME">divisor</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT"> </span><span class="COMM">//if(Math.abs(remainder[c+i])&lt;Math.abs(.00001*divisor[i]*r))remainder[c+i]=0;</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="NAME">quotient</span><span class="PUNC">,</span><span class="NAME">remainder.slice</span><span class="PUNC">(</span><span class="NAME">l</span><span class="PUNC">)</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>129</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>130</span> </span><span class="COMM">//alert(pLongDivision([4,-5,3,1/3+2/27-1],[3,-1]).join('\n'));</span><span class="WHIT">
<span class='line'>131</span>
<span class='line'>132</span> </span><span class="COMM">/*
<span class='line'>133</span> // polynomial multiplication乘法
<span class='line'>134</span> function polynomialMultiplication(pol1,pol2){
<span class='line'>135</span> //for()
<span class='line'>136</span> }
<span class='line'>137</span> */</span><span class="WHIT">
<span class='line'>138</span>
<span class='line'>139</span> </span><span class="COMM">/* Newton Iteration Function 2005/2/26 1:4
<span class='line'>140</span> return [root,誤差]
<span class='line'>141</span> */</span><span class="WHIT">
<span class='line'>142</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">NewtonMethod</span><span class="PUNC">(</span><span class="NAME">polynomial</span><span class="PUNC">,</span><span class="NAME">init</span><span class="PUNC">,</span><span class="NAME">diff</span><span class="PUNC">,</span><span class="NAME">count</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="NAME">d</span><span class="PUNC">,</span><span class="NAME">i</span><span class="PUNC">,</span><span class="NAME">t</span><span class="PUNC">,</span><span class="NAME">l</span><span class="PUNC">,</span><span class="NAME">o</span><span class="PUNC">,</span><span class="NAME">dp</span><span class="PUNC">=</span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">polynomial</span><span class="PUNC">||</span><span class="PUNC">!</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">=</span><span class="NAME">l</span><span class="PUNC">=</span><span class="NAME">polynomial.length</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT"> </span><span class="KEYW">while</span><span class="PUNC">(</span><span class="PUNC">--</span><span class="NAME">d</span><span class="PUNC">)</span><span class="NAME">dp.push</span><span class="PUNC">(</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">++</span><span class="PUNC">]</span><span class="PUNC">*</span><span class="NAME">d</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// dp:微分derivative</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">diff</span><span class="PUNC">)</span><span class="NAME">diff</span><span class="PUNC">=</span><span class="NAME">rootFindingFragment</span><span class="PUNC">;</span><span class="NAME">diff</span><span class="PUNC">=</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">diff</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">count</span><span class="PUNC">)</span><span class="NAME">count</span><span class="PUNC">=</span><span class="NUMB">15</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">=</span><span class="NAME">init</span><span class="PUNC">||</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="NAME">o</span><span class="PUNC">=</span><span class="NAME">diff</span><span class="PUNC">+</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="NAME">l</span><span class="PUNC">--</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>149</span> </span><span class="WHIT"> </span><span class="COMM">//alert(polynomial+'\n'+dp+'\n'+diff+',l:'+l);</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT"> </span><span class="KEYW">while</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">></span><span class="NAME">diff</span><span class="PUNC">&&</span><span class="NAME">count</span><span class="PUNC">--</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>151</span> </span><span class="WHIT"> </span><span class="COMM">//alert(count+':'+x+','+d);</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">=</span><span class="NAME">t</span><span class="PUNC">=</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="NAME">l</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="NAME">d</span><span class="PUNC">=</span><span class="NAME">d</span><span class="PUNC">*</span><span class="NAME">x</span><span class="PUNC">+</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="NAME">t</span><span class="PUNC">=</span><span class="NAME">t</span><span class="PUNC">*</span><span class="NAME">x</span><span class="PUNC">+</span><span class="NAME">dp</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT"> </span><span class="NAME">d</span><span class="PUNC">=</span><span class="NAME">d</span><span class="PUNC">*</span><span class="NAME">x</span><span class="PUNC">+</span><span class="NAME">polynomial</span><span class="PUNC">[</span><span class="NAME">l</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT"> </span><span class="COMM">//alert(d+'/'+t);</span><span class="WHIT">
<span class='line'>155</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">t</span><span class="PUNC">)</span><span class="NAME">d</span><span class="PUNC">/</span><span class="PUNC">=</span><span class="NAME">t</span><span class="PUNC">;</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="NAME">d</span><span class="PUNC">=</span><span class="NUMB">1</span><span class="PUNC">;</span><span class="COMM">//alert();</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT"> </span><span class="NAME">t</span><span class="PUNC">=</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>157</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">&lt;=</span><span class="NAME">t</span><span class="PUNC">)</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">&lt;</span><span class="NAME">rootFindingFragment</span><span class="PUNC">)</span><span class="KEYW">break</span><span class="PUNC">;</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">++</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// test</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT"> </span><span class="NAME">o</span><span class="PUNC">=</span><span class="NAME">t</span><span class="PUNC">,</span><span class="NAME">x</span><span class="PUNC">-</span><span class="PUNC">=</span><span class="NAME">d</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>160</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">,</span><span class="NAME">d</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>161</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>162</span>
<span class='line'>163</span> </span><span class="COMM">// 從roots得到多項式 2005/2/26 0:45</span><span class="WHIT">
<span class='line'>164</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">getPbyR</span><span class="PUNC">(</span><span class="NAME">roots</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">,</span><span class="NAME">r</span><span class="PUNC">,</span><span class="NAME">i</span><span class="PUNC">,</span><span class="NAME">c</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="NAME">l</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">roots</span><span class="PUNC">||</span><span class="PUNC">!</span><span class="PUNC">(</span><span class="NAME">l</span><span class="PUNC">=</span><span class="NAME">roots.length</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>167</span> </span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">=</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="PUNC">-</span><span class="NAME">roots.pop</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT"> </span><span class="KEYW">while</span><span class="PUNC">(</span><span class="PUNC">++</span><span class="NAME">c</span><span class="PUNC">&lt;</span><span class="NAME">l</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">r</span><span class="PUNC">=</span><span class="NAME">roots.pop</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="NAME">p.push</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NAME">r</span><span class="PUNC">*</span><span class="NAME">p</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NAME">c</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="KEYW">while</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="NAME">p</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">-</span><span class="PUNC">=</span><span class="NAME">p</span><span class="PUNC">[</span><span class="PUNC">--</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">*</span><span class="NAME">r</span><span class="PUNC">;</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="NAME">p.push</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>172</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>173</span>
<span class='line'>174</span> </span><span class="COMM">//alert(getPbyR([1,2,3]));</span><span class="WHIT">
<span class='line'>175</span> </span><span class="COMM">//document.write(Newton1(getPbyR([2,32,5,3])));</span><span class="WHIT">
<span class='line'>176</span>
<span class='line'>177</span> </span><span class="COMM">// ↑polynomial -----------------------------------</span><span class="WHIT">
<span class='line'>178</span>
<span class='line'>179</span>
<span class='line'>180</span>
<span class='line'>181</span>
<span class='line'>182</span>
<span class='line'>183</span>
<span class='line'>184</span> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT">
<span class='line'>185</span> </span><span class="WHIT"> </span><span class="NAME">CeL.data.math.polynomial</span><span class="WHIT">
<span class='line'>186</span> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>187</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>188</span>
<span class='line'>189</span>
<span class='line'>190</span> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>191</span>
<span class='line'>192</span> </span></pre></body></html>