2011-04-30 817 views
3

我現在試圖在MATLAB中解決一個指數方程作爲我的任務的一部分。很容易看出,等式在MATLAB中求解指數方程

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

會有兩個解決方案,一個大於零,一個小於零。

然而,只使用求解函數,MATLAB返回一個叫做lambertw函數的東西,它只能eval()到零以下的解決方案,這不是我想要的答案。有人可以幫我嗎?

在此先感謝所有的答案和評論!

p.s.作爲一種選擇,我正在考慮使用牛頓 - 拉夫森方法來解決它,但我不知道速度與解決()相比如何?

Ziyao衛

+0

是'n'常量嗎? – abcd 2011-04-30 01:14:58

+0

@yoda是的!我忘了提及:) – 2011-04-30 01:15:45

回答

1

lambertw是您需要的功能。但是,它是一個多值函數,有幾個分支。您需要爲您的答案選擇正確的分支。關於如何爲解決方案選擇不同的分支,請參閱my answeranother question

1

通過MATLAB提供的答案是正確的,但它給你只有一個分支。 要獲得另一個分支,請使用所提供的答案,但將lambertw(x)替換爲lambertw(k,x)以獲得不同的值k

查看doc of lambertw瞭解更多詳情。

您可以查看Lambert W function on mathworld以瞭解更多信息並可視化不同分支。

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