V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
847272105
V2EX  ›  问与答

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

  •  
  •   847272105 · 2020-05-07 09:13:44 +08:00 · 1378 次点击
    这是一个创建于 1459 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    随便想想,如果有专业的软件还是用专业的软件吧。
    xcstream
        3
    xcstream  
       2020-05-07 09:43:07 +08:00
    wolfarmalpha
    zst
        4
    zst  
       2020-05-07 09:44:04 +08:00 via Android
    mathematica 吧
    douglas1997
        5
    douglas1997  
       2020-05-07 09:58:30 +08:00
    哈哈随手写了一个,仅供参考~

    ```
    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  
       2020-05-07 10:00:18 +08:00
    https://paste.ubuntu.com/p/YFC6R5TKsq/

    好吧, V2EX 不支持代码。。
    noqwerty
        7
    noqwerty  
       2020-05-07 10:10:18 +08:00
    很多语言都有解这类问题的 solver,比如 Python 的 SymPy:

    https://docs.sympy.org/latest/modules/solvers/solvers.html
    princelai
        8
    princelai  
       2020-05-07 10:39:56 +08:00
    看起来像连续复利贴现公式
    847272105
        9
    847272105  
    OP
       2020-05-07 10:47:31 +08:00
    @douglas1997 我测试一下谢谢
    847272105
        10
    847272105  
    OP
       2020-05-07 10:47:59 +08:00
    @xcstream 我看一下谢谢
    847272105
        11
    847272105  
    OP
       2020-05-07 10:48:14 +08:00
    @noqwerty 谢谢
    847272105
        12
    847272105  
    OP
       2020-05-07 10:48:30 +08:00
    @zst 谢谢
    fancy111
        13
    fancy111  
       2020-05-07 10:55:27 +08:00
    方程求解,有现成的网站和程序可以做到。
    847272105
        14
    847272105  
    OP
       2020-05-07 10:58:46 +08:00
    @fancy111 能给一下吗,我找的都不行
    c416593819
        15
    c416593819  
       2020-05-07 11:52:13 +08:00
    Reduce[L_ 1 e^(-t/t1) + L_ 2 e^(-t/t2) + L_ 3 e^(-t/t3) - L ==
    0, t, Reals]
    Mathematic 或者 matlab 都行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   755 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:41 · PVG 04:41 · LAX 13:41 · JFK 16:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.