【问题标题】:Matlab: How to solve the system of nonlinear equations with additional parameters?Matlab:如何求解具有附加参数的非线性方程组?
【发布时间】:2012-08-23 13:48:13
【问题描述】:

我想创建一个函数,在给定两个时间段的数据的情况下,找到 Bass 扩散模型的参数 p 和 q。

模型(方程)如下:

n(T) = p*m + (q-p)*n(T-1) + q/m*n(T-1)^2

在哪里

n(T) = number of addoptions occuring in period T
n(T-1) = number of cumulative adoptions that occured before T
p = coefficient of innovation
q = coefficient of imitation
m = number of eventual adopters

例如,如果 m = 3.000.000 以下年份的数据如下:

2000: n(T) = 820, n(T-1) = 0
2005: n(T) = 25000, n(T-1) = 18000

然后必须求解以下方程组(以确定 p 和 q 的值):

p*m + (q-p)*0 + q/3.000.000 * 0^2 == 820
p*m + (q-p)*18000 + q/3.000.000 * 18000^2 == 25000

通过关注Matlab documentation我尝试创建一个函数Bass:

function F = Bass(m, p, q, cummulativeAdoptersBefore)

F = [p*m + (q-p)*cummulativeAdoptersBefore(1) + q/m*cummulativeAdoptersBefore(1).^2;
    p*m + (q-p)*cummulativeAdoptersBefore(2) + q/m*cummulativeAdoptersBefore(2).^2];


end

应该在 fsolve(@Bass,x0,options) 中使用,但在这种情况下,m、p、q、cummulativeAdoptersBefore(1) 和 cummulativeAdoptersBefore(2) 应该在 x0 中给出,并且所有变量都将被视为未知而不仅仅是后两者。

有谁知道如何求解上述方程组?

谢谢!

【问题讨论】:

  • 所以...你真的只有 1 个方程,n(T)n(T-1) 的数据有几个 T。如果我错了,请纠正我,但这听起来很像你没有这样做。您确定 lsqcurvefit 不是更适合您的问题吗? fsolve 用于不同方程的系统...
  • @RodyOldenhuis:你是对的。我会检查 lsqcurvefit。谢谢!

标签: matlab


【解决方案1】:

fsolve() 试图最小化您作为参数提供的函数。因此,您必须将方程式更改为

p*m + (q-p)*0     + q/3.000.000 * 0^2     - 820   == 0
p*m + (q-p)*18000 + q/3.000.000 * 18000^2 - 25000 == 0

在 Matlab 中的语法

function F = Bass(m, p, q, cumulativeAdoptersBefore, cumulativeAdoptersAfter)

    F = [p*m + (q-p)*cumulativeAdoptersBefore(1) ...
             + q/m  *cumulativeAdoptersBefore(1).^2 
             - cumulativeAdoptersAfter(1);
         p*m + (q-p)*cumulativeAdoptersBefore(2) ...
             + q/m  *cumulativeAdoptersBefore(2).^2 
             - cumulativeAdoptersAfter(2)];
end

注意:您的 Bass 函数中有错字(乘法而不是求和)。

现在你有了一个函数,它接受的参数比未知数多。 一种选择是创建一个匿名函数,它只将未知数作为参数,并通过闭包修复其他参数。 为了适应未知数 pq,您可以使用类似

cumulativeAdoptersBefore = [0, 1800];
cumulativeAdoptersAfter = [820, 25000];
m = 3e6;
x = [0, 0]; %# Probably, this is no good starting guess.
xopt = fsolve(@(x) Bass(m, x(1), x(2), cumulativeAdoptersBefore, cumulativeAdoptersAfter), x0);

所以fsolve() 看到一个函数只接受一个参数(一个包含两个元素的向量),它还返回一个向量值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 2021-12-13
    相关资源
    最近更新 更多