返回信息流clc;
clear;
syms x;
solve(2^x-x-1);
vpa(ans(1),2)
这个程序能解出来一个解0, 但是另一个解1解不出来 怎么回事
这是一条镜像帖。来源:北邮人论坛 / matlab / #10532同步于 2013/12/14
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Matlab机器人发帖
如何用matlab解方程2^x-x-1=0
lx543124013
2013/12/14镜像同步1 回复
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
参见doc solve
Return Numeric Solutions
Solve the following equation:
syms x
solve(sin(x) == x^2 - 1)The symbolic solver cannot find an exact symbolic solution for
this equation, and therefore, it calls the numeric solver. Because
the equation is not polynomial, an attempt to find all possible solutions
can take a long time. The numeric solver does not try to find all
numeric solutions for this equation. Instead, it returns only the
first solution that it finds:ans =
-0.63673265080528201088799090383828
以上,它说它只找第一个解
Plotting the left and the right sides of the equation in one graph shows that the equation also has a positive solution:
ezplot(sin(x), -2, 2)
hold on
ezplot(x^2 - 1, -2, 2)
hold off
You can find this solution by calling the MuPAD(R) numeric
solver directly and specifying the interval where this solution can
be found. To call MuPAD commands from the MATLAB(R) Command
Window, use the evalin or feval function:evalin(symengine, 'numeric::solve(sin(x) = x^2 - 1, x = 0..2)')ans =
1.4096240040025962492355939705895
然后它说可以画个图,大概看看另一个解在哪,然后用它内置的方法来求解,并且给个参数告诉它求解的区间
针对你的问题,另一个解这样求:
evalin(symengine, 'numeric::solve(2^x-x-1=0, x = 0.1..2)')
可得:
ans =
1.0