Title: continued fraction Post by: Europa on November 05, 2009, 06:41:28 PM สวัสดีครับ ผมมีคำถามเกี่ยวกับ การใช้ mathematica6.0 ในการ evaluate ค่าของ continued fraction แบบนี้ครับ
![]() จะเห็นว่า มัน รัน n ย้อนลงไปเรื่อยๆๆ ผมไม่รู้ว่าจะสั่งให้ mathematica เข้าใจยังไง Title: Re: continued fraction Post by: Bright on November 09, 2009, 05:36:02 PM ลองดูตัวอย่างจากในคำสั่ง ContinuedFraction , FromContinuedFraction หรือ Nest ครับ
ผมว่าความยากของปัญหาคุณมันอยู่ที่ index ในตัวแปร alpha beta, gamma ผมยังคิดไม่ออกครับว่าจะทำยังไงครับ :) อันนี้เป็นฟังก์ชั่น สำหรับที่ผมใช้สำหรับสร้างตัวส่วน below[i_] := Quiet[If[i == 0, \[Beta][[n]] - \[Alpha][[n - 1]] \[Gamma][[n - 1]], \[Beta][[n - i]] - \[Alpha][[n - i - 1]] \[Gamma][[n - i]] ]] แต่อันนี้ยังไม่ถูกครับเพราะ index ยังเหมือนกัน แต่คุณอาจจะมีทางที่ดีกว่านี้ก็ได้ครับ Quiet[Nest[\[Beta][[n]] - \[Alpha][[n - 1]] \[Gamma][[n - 1]]/# &, below[0], 5]] ถ้าคิดออกจะกลับมาตอบให้ครับ :) Title: Re: continued fraction Post by: Bright on November 15, 2009, 01:14:24 AM ลองดูแบบนี้แล้วกันครับ index น่าจะถูกแล้ว
below1[i_] := Quiet[If[i == 0, \[Alpha][[n - 1]] \[Gamma][[n - 1]], \[Alpha][[n - i - 1]] \[Gamma][[n - i]]]]; frac[j_] := Quiet[tmp1 = below1[j]; For[m = j, m > 0, m--, tmp1 = below1[m - 1]/(\[Beta][[n - m]] - tmp1) ]; \[Beta][[n]] - tmp1 ] ลองทดสอบโดยพิมพ์ frac[5] ดูครับ มันจะแสดงส่วนจนถึง \[beta][[n-5]] ครับ Title: Re: continued fraction Post by: Bright on August 19, 2010, 04:27:46 PM ลองวิธีเขียนแบบนี้ก็ได้ครับ แต่ index ของแกรมม่ายังไม่ถูก ;D ยังไงลองเล่นดูเป็นแนวทางนะครับ
continuedfractionX[{b0_, l_List?MatrixQ}] := b0 - Fold[#2[[1]] #2[[3]]/(#1 + #2[[2]]) &, 0, Reverse[l]] continuedfractionX[{b0_, {}}] := b0 continuedfractionX[{b[0], Table[{a[ i ], b [i ], c[ i - 1 ]}, {i, 5}]}] /. x_[y_] :> x[n - y] |