Python簡單求解高階方程的數值解

來源:互聯網
上載者:User

#-*-encoding:utf-8-*-<br />#插值法求解問題<br />#http://zhidao.baidu.com/question/24991328?si=2<br />def getResult(r):<br /> tmp1 = 59 * ((1 + r) **(-1))<br /> tmp2 = 59 * ((1 + r) **(-2))<br /> tmp3 = 59 * ((1 + r) **(-3))<br /> tmp4 = 59 * ((1 + r) **(-4))<br /> tmp5 = (59 + 1250) * ((1 + r) **(-5))<br /> tmp6 = -1000<br /> x = sum([tmp1, tmp2, tmp3, tmp4, tmp5, tmp6])<br /> return(x)<br />def getNext(a, b):<br /> #其中a為區間下限、b為區間上限<br /> m = (b + a) / 2<br /> tmpa = getResult(a)<br /> tmpb = getResult(b)<br /> tmpm = getResult(m)<br /> tmp1, tmp2 = 0, 0</p><p> if tmpa * tmpb > 0:<br /> tmp1 = max(a, b)<br /> tmp2 = tmp1 + abs(b-a)<br /> else:<br /> if tmpa * tmpm > 0:<br /> tmp1 = m<br /> tmp2 = b<br /> else:<br /> tmp1 = a<br /> tmp2 = m<br /> #print(a,m,b)<br /> #print(tmpa,tmpm,tmpb)<br /> return(tmp1, tmp2)<br />def write(a,b):<br /> f = open('data.txt', 'a')<br /> f.write(str(a) + '/t' + str(b) + "/n")<br /> f.close()<br />if __name__ == '__main__':<br /> little, big = 0.01, 0.20<br /> i = 1<br /> while i < 50:<br /> little, big = getNext(little, big)<br /> write(little, big)<br /> i += 1 該解法的理論基礎是初等微積分中的羅爾定理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.