【问题标题】:Maxima can't solve lineare equation with sum千里马不能用总和求解线性方程
【发布时间】:2018-05-08 20:26:12
【问题描述】:

我正在尝试用最大值计算线性回归方程,但最大值无法求解线性系统:

Maxima 5.38.1 http://maxima.sourceforge.net
using Lisp GNU Common Lisp (GCL) GCL 2.6.12
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) e: sum((y[i] - (a*x[i]+b))^2, i, 1, n);
                             n
                            ====
                            \                    2
(%o1)                        >    (y  - a x  - b)
                            /       i      i
                            ====
                            i = 1
(%i2) dea: diff(e, a, 1);
                              n
                             ====
                             \
(%o2)                    - 2  >    x  (y  - a x  - b)
                             /      i   i      i
                             ====
                             i = 1
(%i3) deb: diff(e, b, 1);
                                n
                               ====
                               \
(%o3)                      - 2  >    (y  - a x  - b)
                               /       i      i
                               ====
                               i = 1
(%i4) linsolve([dea, deb], [a, b]);
(%o4)                                 []

为什么是空的?据我所知,最大值无法解决与其他一些变量相加的变量。我该如何解决?我必须使用其他函数还是必须重新排序我的方程式?

【问题讨论】:

    标签: maxima


    【解决方案1】:

    你可以声明sum线性。

    declare(sum, linear);
    e: sum((y[i] - (a*x[i]+b))^2, i, 1, n);
    e: expand(e);
    
    dea: diff(e, a);
    deb: diff(e, b);
    
    linsolve([dea, deb], [a, b]);
    

    输出

                n                 n         n
                ====              ====      ====
                \                 \         \
               ( >    x  y ) n - ( >    x )  >    y
                /      i  i       /      i  /      i
                ====              ====      ====
                i = 1             i = 1     i = 1
    (%o7) [a = -------------------------------------, 
                      n              n
                     ====           ====
                     \      2       \        2
                    ( >    x ) n - ( >    x )
                     /      i       /      i
                     ====           ====
                     i = 1          i = 1
                                        n         n              n         n
                                       ====      ====           ====      ====
                                       \         \              \      2  \
                                      ( >    x )  >    x  y  - ( >    x )  >    y
                                       /      i  /      i  i    /      i  /      i
                                       ====      ====           ====      ====
                                       i = 1     i = 1          i = 1     i = 1
                                b = - --------------------------------------------]
                                                 n              n
                                                ====           ====
                                                \      2       \        2
                                               ( >    x ) n - ( >    x )
                                                /      i       /      i
                                                ====           ====
                                                i = 1          i = 1
    

    或者用符号表示和:

    declare(sum, linear) $
    
    tellsimpafter('sum(x[i],i,1,n), sx) $
    tellsimpafter('sum(y[i],i,1,n), sy) $
    tellsimpafter('sum(y[i]^2,i,1,n), sy2) $
    tellsimpafter('sum(x[i]^2,i,1,n), sx2) $
    tellsimpafter('sum(x[i]*y[i],i,1,n), sxy) $
    
    e: sum((y[i] - (a*x[i]+b))^2, i, 1, n);
    e: expand(e);
    
    dea: diff(e, a);
    deb: diff(e, b);
    
    linsolve([dea, deb], [a, b]);
    
                           n sxy - sx sy        sx sxy - sx2 sy
    (%o22)            [a = -------------, b = - ---------------]
                                      2                     2
                            n sx2 - sx            n sx2 - sx
    

    【讨论】:

    • 你能解释一下问题和解决方法吗?
    • sum 默认不是线性的,solve 也不知道如何处理。
    • 有没有办法将 sum 声明回非线性?
    • @Lori remove(sum, linear);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-05
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 2019-10-02
    相关资源
    最近更新 更多