MATLAB |根据均值和概率区间计算 gamma dist 参数

发布于 2024-09-18 07:57:23 字数 324 浏览 6 评论 0原文

我有一个包含 2 个未知数的 2 个方程组,我想使用 MATLAB 求解该方程组,但不知道具体如何编程。我已经获得了一些有关伽马分布的信息(平均值为 1.86,1.61 和 2.11 之间的 90% 间隔),最终想要获得平均值和方差。我知道我可以使用正态近似,但我宁愿求解 A 和 B、伽马分布的形状和尺度参数,并以这种方式找到均值和方差。在伪 MATLAB 代码中,我想解决这个问题:

gamcdf(2.11, A, B) - gamcdf(1.61, A, B) = 0.90;
A*B = 1.86;

你会如何解决这个问题?如果有帮助的话,我有符号数学工具箱。

I have a system of 2 equations in 2 unknowns that I want to solve using MATLAB but don't know exactly how to program. I've been given some information about a gamma distribution (mean of 1.86, 90% interval between 1.61 and 2.11) and ultimately want to get the mean and variance. I know that I could use the normal approximation but I'd rather solve for A and B, the shape and scale parameters of the gamma distribution, and find the mean and variance that way. In pseudo-MATLAB code I would want to solve this:

gamcdf(2.11, A, B) - gamcdf(1.61, A, B) = 0.90;
A*B = 1.86;

How would you go about solving this? I have the symbolic math toolbox if that helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神也荒唐 2024-09-25 07:57:23

平均值为 A*B。那么你能用平均值(mu)和 B 来求解 A 吗?

A = mu/B

当然,除非你认识 B,否则这没有任何好处。是吗?

看你第一个表情。可以代替吗?

gamcdf(2.11, mu/B, B) - gamcdf(1.61, mu/B, B) = 0.90

这会让你更亲近吗?也许。除了不完整的伽马函数本身之外,不会有任何有用的符号解决方案可用。如何在 matlab 中用数值方法求解一个未知数方程?使用 fzero。

当然,fzero 寻找零值。但减去 0.90,问题就解决了。

我们可以定义一个 fzero 可以使用的函数吗?使用函数句柄。

>> mu = 1.86;
>> gamfun = @(B) gamcdf(2.11, mu/B, B) - gamcdf(1.61, mu/B, B) - 0.90;

所以尝试一下吧。在我们这样做之前,我总是建议先策划一些事情。

>> ezplot(gamfun)

唔。该图表明,可能很难找到函数的零点。如果您尝试一下,您会发现这里需要良好的 fzero 起始值。

对我的第一次尝试感到抱歉。更好的 fzero 起始值,加上更多的绘图确实给出了产生所需形状的伽玛分布。

>> B = fzero(gamfun,[.0000001,.1])
B =
        0.0124760672290871
>> A = mu/B
A =
          149.085442218805
>> ezplot(@(x) gampdf(x,A,B))

事实上,这是一条非常“正常”的曲线,即高斯曲线。

The mean is A*B. So can you solve for perhaps A in terms of the mean(mu) and B?

A = mu/B

Of course, this does no good unless you knew B. Or does it?

Look at your first expression. Can you substitute?

gamcdf(2.11, mu/B, B) - gamcdf(1.61, mu/B, B) = 0.90

Does this get you any closer? Perhaps. There will be no useful symbolic solution available, except in terms of the incomplete gamma function itself. How do you solve a single equation numerically in one unknown in matlab? Use fzero.

Of course, fzero looks for a zero value. But by subtracting 0.90, that is resolved.

Can we define a function that fzero can use? Use a function handle.

>> mu = 1.86;
>> gamfun = @(B) gamcdf(2.11, mu/B, B) - gamcdf(1.61, mu/B, B) - 0.90;

So try it. Before we do that, I always recommend plotting things.

>> ezplot(gamfun)

Hmm. That plot suggests that it might be difficult to find a zero of your function. If you do try it, you will find that good starting values for fzero are necessary here.

Sorry about my first try. Better starting values for fzero, plus some more plotting does give a gamma distribution that yields the desired shape.

>> B = fzero(gamfun,[.0000001,.1])
B =
        0.0124760672290871
>> A = mu/B
A =
          149.085442218805
>> ezplot(@(x) gampdf(x,A,B))

In fact this is a very "normal", i.e, Gaussian, looking curve.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文