超越方程 [英] Transcendental Equation

查看:145
本文介绍了超越方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临着解决先验方程的任务:

I've faced a task to solve a transcendental equation:

K = K0*(exp(-t*B)/1+L*B)

变量"B"未知.我必须首先为B使用下一个表达式:

Variable 'B' is unknown. I have to take the next expression for B for a first step:

B = (K0-1)/(L+t)

对于第二步和所有后续步骤,我必须将B计算为:

For the second step and for all the next steps I have to calculate B as:

B = -(1/t)*ln((1+L*B)/K0)

当B的上一个值与当前值之间的相对差不超过例如1%时,迭代将停止.所得的B应该使第一个方程的右边等于1. 如何使用python做到这一点?我从scipy那里听说过零查找程序,但是我确实更喜欢一些普通的编码(这将有助于我更好地理解事物).我已经尝试了while循环.当第一个方程式中的K足够接近1.0时,我可以编写一个循环来迭代并停止迭代:

The iteration stops when relative difference between the previous and the current value for B doesn't exceed, say, 1%. The resulting B should make the first equation right part be equal to 1. How can I do it with python? I've heard about zero-finding routines from scipy, but I really would prefer some ordinary coding (It would help me to understand things better). I've tried the while loop. I can write a loop to iterate and stop iterating when K from the first equation is close enough to 1.0:

kinf = 1.123456e+00

tau = 2.832995e+01

L2 = 3.745903e+00

i = 1

b2 = (kinf-1)/(L2+tau)

def iterate():
    b = b2
    i = 1
    print "iteration no.{:.1f}; B^2 = {:.06e}; delta = {:.03f}".format(i, b, kinf*((exp(-tau*b))/(1+L2*b)) - 1.0)
    while abs(kinf*((exp(-tau*b))/(1+L2*b))-1.0)>0.0001:
        b = -(1/tau)*log((1+L2*b)/kinf)
        i+=1
        print "iteration no.{:.1f}; B^2 = {:.06e}; delta = {:.03f}".format(i, b, kinf*((exp(-tau*b))/(1+L2*b)) - 1.0)

但是我不明白,如何比较B的先前值和当前值.我想,这个问题是经典的问题之一,但是我非常感谢.

But I can't understand, how do I compare previous and current values of B. I suppose, this problem is one of classic ones, but I appreciate any help.

UPD: 谢谢您的帮助! 我现在正在做吗?

UPD: Thank you for your help! Am I doing it right now?

def iterate():
b0 = (kinf-1)/(L2+tau)
bold = b0
b = -(1/tau)*log((1+L2*b0)/kinf)
bnew = b
diff = ((bnew-bold)/bnew)*100
while abs(diff)>=0.01:
    print 'previous B^2 = {:.06e}'.format(bold)
    bnew = -(1/tau)*log((1+L2*bold)/kinf)
    print 'B^2 = {:.06e}'.format(bnew)
    diff = ((bnew-bold)/bnew)*100
    print 'delta = {:.06e}'.format(diff)
    bold = bnew

推荐答案

不要在此行覆盖b(您将通过这种方式释放b的旧值):

Don't override b in this line (you'll loose the old value of b this way):

b = -(1/tau)*log((1+L2*b)/kinf) # the old value of b gets lost here

相反,您可以在while循环中执行此操作:

Instead you can do this within your while-loop:

b_new = -(1/tau)*log((1+L2*b)/kinf)
b_delta = b_new - b
# do whatever you want with b_delta and finally override the old b with the new b
b = b_new

这篇关于超越方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆