在下面的代碼中,我在數值上求解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
是'n'常量嗎? – abcd 2011-04-30 01:14:58
@yoda是的!我忘了提及:) – 2011-04-30 01:15:45