• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users




(1) 2 »


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#11
版主
版主


查看用戶資訊
颱風大大,
佩服,佩服,泰勒展開式 - 早就還給敎工數的老師了。

發表於: 2008/4/9 17:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#10
資深會員
資深會員


查看用戶資訊
ArcSin[x] 作泰勒展開,得 x + (x^3)/6 +..... 這裡只取前兩項
這裡的x範圍限定為[0,1],因為 ArcSin[x]=θ
合併兩式 x+(x^3)/6=θ 設 x 為已知條件,假設為 x=0.5
得θ=0.52083(rad),換算成deg大約為29.8416度,誤差<1%
ArcCos()與ArcTan()依此類推。

值得注意的是當x趨近於1時,θ誤差會成級數倍增加,比如x=0.99
時誤差為14%,此法 要不就只適用於x與θ小的情況(最常見於鐘擺\r
問題的分析上),要不就增加計算項次,比如十項時減為5%,
但已經失去手算的意義。

手算開方根,最簡單使用十分逼近法,上面的範例程式就是。

送給你一些式子,自已試吧

ArcSin[x]=x + x^3/6 + (3 x^5)/40 + (5 x^7)/112 + (35 x^9)/1152
0< x < 1 對應 0 < θ < π/2

ArcCos[x]=π/2 - x - x^3/6 - (3 x^5)/40 - (5 x^7)/112 - (35 x^9)/1152
0< x < 1 對應 0 < θ < π/2

ArcTan[x]=x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - x^11/11 + x^13/13
-1 < x < 1 對應 -π/4 < θ < π/4

發表於: 2008/4/9 16:22
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#9
版主
版主


查看用戶資訊
用手算開根號,我只記的應該是國中的時候有教過...算一算已經30年沒用筆、紙開更號了,也許早就忘的一乾二淨了,還好有計算機一樣可以完成。
看 Heardware Stack 可以在 "view" 下找到的。

發表於: 2008/4/9 15:54
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#8
資深會員
資深會員


查看用戶資訊
多謝 C_H_M 大大的秘技,誤差約小於 0.01已經夠用了,我只需要算到小數點一位就可以了。

請問一下這種程式是不是是不是將手算開根號的方式用程式來表達?如果在沒有計算機的情形下,能否用手算開根號和計算反三角函數 atan ?謝謝。

發表於: 2008/4/9 9:15
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#7
中級會員
中級會員


查看用戶資訊
提供另一個開方的函數給你參考.
不過這個函數傳回的數值比較會出現誤差,但約小於 0.01

#include <PIC1687x.h>

[color=CC0000]
bank2 double sqr_x0sqr_x1sqr_x2;
bank2 double sqr_2;
bank2 unsigned char sqr_c;

double sqr_rough(double x)
{
 if(
<= 0)  return 0;

 if(
1)
   { 
sqr_x0 0;
     
sqr_x2 1.0;
   }
 else
   { 
sqr_x0 1.0;
     
sqr_x2 10.0;
     
sqr_2 100;
     while(
sqr_2 1)
          { 
sqr_2 /= 100;
            
sqr_x0 *= 10;
            
sqr_x2 *= 10;
          }
     if(
sqr_2 0.25)  sqr_x0 *= 5;
     else  
sqr_x2 /= 2;
   }

 for(
sqr_c 0sqr_c 15sqr_c++)
    { 
sqr_x1 = (sqr_x0 sqr_x2) / 2;
      
sqr_2 sqr_x1 sqr_x1;
      if(
sqr_2 == x)
        { 
sqr_x0 sqr_x1;
          
sqr_x2 sqr_x1;
        }
      if(
sqr_2 x)  sqr_x0 sqr_x1;
      if(
sqr_2 x)  sqr_x2 sqr_x1;
    }
 return (
sqr_x0 sqr_x2) / 2;
}
[/
color]

double sqrt_root;

void main()
{
 
sqrt_root sqr_rough(2);
 
sqrt_root sqr_rough(900);
 
sqrt_root sqr_rough(49);
 
sqrt_root sqr_rough(100);
 
sqrt_root sqr_rough(2500);
 
sqrt_root sqr_rough(1500);
 
sqrt_root sqr_rough(1000);
 
sqrt_root sqr_rough(6250000);
 
sqrt_root sqr_rough(4000000);
}

發表於: 2008/4/8 23:43
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#6
資深會員
資深會員


查看用戶資訊
謝謝版大的建議:

原來用 MPLAB SIM 配合設定中斷點除錯的方式,可以檢查堆疊所使用的層數。請問一下:要在哪個視窗中檢查呢?

我現在比較頭大的問題是,連 Compiler 都不過了,所以無法執行 MPLAB SIM ,傷腦筋。

發表於: 2008/4/4 8:31
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#5
版主
版主


查看用戶資訊
PISR,

如果你的計算要在短時間內完成的話,可以考慮改用 PIC24FJ (16 MIPS) 或 PIC24HJ (40 MIPS) 的 16-bit PIC,而且 C30 在做數學運算也比較強。因為你是用 C 寫的程式,轉移上是很簡單的。

另外,要知道是否 Stack Overflow 了,可以用 MPLAB SIM 配合設定中斷點除錯的方式,直接檢查堆疊所使用的層數。以 PIC16F 而言,程式最多只能呼叫到七層,你必須保留一層(第八層)給中斷使用。單使用 ICD2 是無法知道使用了幾層的 Stack 的。

發表於: 2008/4/3 15:15
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#4
資深會員
資深會員


查看用戶資訊
PIC24是強一些, 不是強很多, 因為只多了有號數乘法, 但卻是18MCU的相同方式, 您的應用確實24即可, 要更快, 就得33或是30, 而你用16是完全沒有乘法器, 太難為它嚕~~

發表於: 2008/3/31 17:34
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#3
資深會員
資深會員


查看用戶資訊
請問一下:
PIC24系列16位元的單晶片的數學運算功能是不是強很多?
因為我一直都是用8位元的,16位元的單晶片還沒用過。

發表於: 2008/3/31 17:27
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 呼叫過多數學函數導致 RAM overflow 請問如何解決?
#2
資深會員
資深會員


查看用戶資訊
我說,這就像用50cc的小綿羊載一隻大豬公上街逛一般。
再說白一些,pic16「不適合」搞這種事,雖然也並非不可能…
最少也得把device設為pic24吧?

如果只是想純粹練習數學,matlab、mathematica、maple是本行業的三巨頭,選一個來用吧。

如果只是想純粹練習C語言的話,作木工起家不大又不硬公司的vs2008正免費下載供個人研究使用,花個時間裝一下,也遠比你現在用的工具強上太多了。

發表於: 2008/3/31 16:12
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------