847272105
V2EX  ›  问与答

各位大佬,求助复合指数函数计算

  •  
  •   847272105 · May 7, 2020 · 1939 views
    This topic created in 2281 days ago, the information mentioned may be changed or developed.

    数函:L=L_1 e^(-t/t1)+L_2 e^(-t/t2)+L_3 e^(-t/t3) 已知 L,L1 、L2 、L3 、t1 、t2 、t3 () 求:t 小弟不才,请大佬帮忙看一下 是否有软件可以计算

    15 replies    2020-05-07 11:52:13 +08:00
    douglas1997
        1
    douglas1997  
       May 7, 2020
    我个人感觉用牛顿法或者梯度下降法应该可以解决这个问题吧,可以尝试一下。给定一个 t,然后看 L(t),再看 L(t)-L 以及 L'(t),之后不断迭代即可。
    douglas1997
        2
    douglas1997  
       May 7, 2020
    哈哈突然想到一个想法,你用 PyTorch,将这个式子写出来,然后用梯度下降去优化,只有一个可导参数 t,估计迭代 20 次就能得到结果。存在的问题可能是解不是唯一的问题。

    随便想想,如果有专业的软件还是用专业的软件吧。
    xcstream
        3
    xcstream  
       May 7, 2020
    wolfarmalpha
    zst
        4
    zst  
       May 7, 2020 via Android
    mathematica 吧
    douglas1997
        5
    douglas1997  
       May 7, 2020
    哈哈随手写了一个,仅供参考~

    ```
    import torch

    import math


    # y = 0.11, t=20
    def fx2(t):
    return 2*math.exp(-t)+3*math.exp(-t/2)+6*math.exp(-t/5)

    def fx(inputs):
    return inputs[0]*torch.exp(inputs[1]*t)+inputs[2]*torch.exp(inputs[3]*t)+inputs[4]*torch.exp(inputs[5]*t)

    inputs = torch.Tensor([2, -1, 3, -0.5, 6, -0.2])

    t = torch.ones(1, requires_grad=True)
    y = 0.11

    optimizer = torch.optim.SGD(params=(t,), lr=0.5)
    criterion = torch.nn.MSELoss()

    for i in range(2000):
    optimizer.zero_grad()

    y_pred = fx(inputs)
    loss = criterion(y_pred, torch.Tensor([y]))
    loss.backward()
    optimizer.step()
    print (i, loss)

    print (t)
    final_t = t.item()
    print ("t: {}, y: {}, y_pred: {}".format(final_t, y, fx2(final_t)))
    ```
    最后结果`t: 20.136356353759766, y: 0.11, y_pred: 0.10706461213461692`。
    douglas1997
        6
    douglas1997  
       May 7, 2020
    https://paste.ubuntu.com/p/YFC6R5TKsq/

    好吧, V2EX 不支持代码。。
    noqwerty
        7
    noqwerty  
       May 7, 2020
    很多语言都有解这类问题的 solver,比如 Python 的 SymPy:

    https://docs.sympy.org/latest/modules/solvers/solvers.html
    princelai
        8
    princelai  
       May 7, 2020
    看起来像连续复利贴现公式
    847272105
        9
    847272105  
    OP
       May 7, 2020
    @douglas1997 我测试一下谢谢
    847272105
        10
    847272105  
    OP
       May 7, 2020
    @xcstream 我看一下谢谢
    847272105
        11
    847272105  
    OP
       May 7, 2020
    @noqwerty 谢谢
    847272105
        12
    847272105  
    OP
       May 7, 2020
    @zst 谢谢
    fancy111
        13
    fancy111  
       May 7, 2020
    方程求解,有现成的网站和程序可以做到。
    847272105
        14
    847272105  
    OP
       May 7, 2020
    @fancy111 能给一下吗,我找的都不行
    c416593819
        15
    c416593819  
       May 7, 2020
    Reduce[L_ 1 e^(-t/t1) + L_ 2 e^(-t/t2) + L_ 3 e^(-t/t3) - L ==
    0, t, Reals]
    Mathematic 或者 matlab 都行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   981 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 22:29 · PVG 06:29 · LAX 15:29 · JFK 18:29
    ♥ Do have faith in what you're doing.