在MATLAB中求解指数方程

时间:2011-04-30 01:11:54

标签: matlab scientific-computing equation

我现在正试图在MATLAB中解决指数方程,作为我的任务的一部分。很容易看出方程式

exp(-t)+t*exp(-t)-n=0

会有两个解决方案,一个大于零,一个小一些。

然而,仅使用求解函数,MATLAB返回一个名为lambertw函数的东西,它只能eval()到零以下的解决方案,这恰好不是我想要的答案。有人可以帮我吗?

提前感谢所有答案和评论!

P.S。作为替代方案,我正在考虑使用Newton-Raphson方法来解决它,但我想知道如何将速度与solve()进行比较?

Ziyao Wei

3 个答案:

答案 0 :(得分:2)

在下面的代码中,我在数字上求解n=0.5(常数)的等式,但是对于您选择的其他值,它应该是相似的。

注意SOLVE函数如何仅返回找到的第一个解决方案。因此,我直接调用MuPAD引擎,并指定每次搜索解决方案的时间间隔:

%# lets plot the function: f(x) = exp(-x)+x*exp(-x)
h(1) = ezplot('0.5', [-1.5 10]); hold on
h(2) = ezplot('exp(-x)+x.*exp(-x)', [-1.5 10]);
set(h(1), 'LineStyle',':', 'Color','r')
legend(h, 'y = 0.5', 'y = exp(-x)+x.*exp(-x)')

%# The numeric solver only returns the first solution that it finds
x = solve('exp(-x)+x*exp(-x)=0.5')
x = vpa(x)

%# we can call the MuPAD solver and give the interval where solution can be found
x1 = evalin(symengine, 'numeric::solve(exp(-x)+x*exp(-x)=0.5, x = -1..0)')
x2 = evalin(symengine, 'numeric::solve(exp(-x)+x*exp(-x)=0.5, x = 0..3)')

%# show the solutions on the plot
plot([x1 x2], 0.5, 'ro')

SOLVE返回的解决方案:

x =
- 1.0*lambertw(0, -1/(2*exp(1))) - 1.0
x =
-0.76803904701346556525568352607755

MuPAD数字解决方案:

x1 =
-0.76803904701346556525568352607755
x2 =
1.6783469900166606534128845120945

enter image description here

答案 1 :(得分:1)

matlab提供的答案是正确的,但它只给你一个分支。 要获得另一个分支,请使用提供的答案,但将lambertw(x)替换为lambertw(k,x),以获取k的不同值。

有关详细信息,请参阅doc of lambertw

您可以查看Lambert W function on mathworld以了解更多信息,并可视化不同的分支。

答案 2 :(得分:1)

lambertw是您需要的功能。但是,它是一个多值函数,并有几个分支。您需要为您的答案选择正确的分支。有关如何为解决方案选择其他分支,请参阅my answeranother question

相关问题