Matlab解决功能有问题吗? [英] Issue with Matlab solve function?

查看:121
本文介绍了Matlab解决功能有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令

syms x real;
f = @(x) log(x^2)*exp(-1/(x^2));
fp(x) = diff(f(x),x);
fpp(x) = diff(fp(x),x);

solve(fpp(x)>0,x,'Real',true)

返回结果

solve([0.0<(8.0 * exp(-1.0/x ^ 2))/x ^ 4-(2.0 * exp(-1.0/x ^ 2))/x ^ 2- (6.0 * log(x ^ 2)* exp(-1.0/x ^ 2))/x ^ 4 +(4.0 * log(x ^ 2)* exp(-1.0/x ^ 2))/x ^ 6] , [x == RD_NINF..RD_INF])

solve([0.0 < (8.0*exp(-1.0/x^2))/x^4 - (2.0*exp(-1.0/x^2))/x^2 - (6.0*log(x^2)*exp(-1.0/x^2))/x^4 + (4.0*log(x^2)*exp(-1.0/x^2))/x^6], [x == RD_NINF..RD_INF])

这不是我期望的.

第一个问题:是否可以强制Matlab的solve返回所有解决方案的集合?

The first question: Is it possible to force Matlab's solve to return the set of all solutions?

(这与此问题.)而且,当我尝试求解方程式

(This is related to this question.) Moreover, when I try to solve the equation

solve(fpp(x)==0,x,'Real',true)

返回

ans =
-1.5056100417680902125994180096313

ans =
-1.5056100417680902125994180096313

我不满意,因为没有返回所有解决方案(它们分别是从WolframAlpha获得的-1.5056、1.5056,-0.5663和0.5663).

I am not satisfied since all solutions are not returned (they are approximately -1.5056, 1.5056, -0.5663 and 0.5663 obtained from WolframAlpha).

我知道vpasolve有一些初步的猜测可以解决这个问题.但是,我不知道我通常如何找到初始猜测值来获取所有解,这是我的第二个问题.

I know that vpasolve with some initial guess can handle this. But, I have no idea how I can generally find initial guessed values to obtain all solutions, which is my second question.

欢迎其他解决这些问题的方法或建议.

Other solutions or suggestions for solving these problems are welcomed.

推荐答案

正如我在上面的评论中所指出的,文档:数值求解器不会尝试查找方程的所有数值解.相反,它仅返回找到的第一个解."

As I indicated in my comment above, sym/solve is primarily meant to solve for analytic solutions of equations. When this fails, it tries to find a numeric solution. Some equations can have an infinite number of numeric solutions (e.g., periodic equations), and thus, as per the documentation: "The numeric solver does not try to find all numeric solutions for [the] equation. Instead, it returns only the first solution that it finds."

但是,人们可以访问 MuPAD的功能在Matlab中. MuPAD的 numeric :: solve 函数还具有其他一些功能.特别是'AllRealRoots'选项.就您而言:

However, one can access the features of MuPAD from within Matlab. MuPAD's numeric::solve function has several additional capabilities. In particular is the 'AllRealRoots' option. In your case:

syms x real;
f = @(x)log(x^2)*exp(-1/(x^2));
fp(x) = diff(f(x),x);
fpp(x) = diff(fp(x),x);
s = feval(symengine,'numeric::solve',fpp(x)==0,x,'AllRealRoots')

返回

s =

[ -1.5056102995536617698689500437312, -0.56633904710786569620564475006904, 0.56633904710786569620564475006904, 1.5056102995536617698689500437312]

以及警告消息.

我对这个问题的答案提供了使用各种MuPAD求解器的其他方法,特别是如果您可以隔离并括起根的话

My answer to this question provides other way that various MuPAD solvers can be used, particularly if you can isolate and bracket your roots.

除了告诉您函数在何处更改符号外,上面的内容不能直接帮助您解决不平等问题.对于那些您可以尝试:

The above is not going to directly help with your inequalities other than telling you where the function changes sign. For those you could try:

s = feval(symengine,'solve',fpp(x)>0,x,'Real')

返回

s =

(Dom::Interval(0, Inf) union Dom::Interval(-Inf, 0)) intersect solve(0 < 2*log(x^2) - 3*x^2*log(x^2) + 4*x^2 - x^4, x, Real)

尝试将此函数与fpp一起绘制.

Try plotting this function along with fpp.

虽然这本身不是漏洞,但相对于MuPAD的solve,MathWorks可能仍对sym/solve(以及基础symobj::solvefull)的这种行为差异和较差的性能感兴趣.如果愿意,可以提交错误报告.对于我的一生,我不明白为什么他们不能更好地统一Matlab的这些部分.从用户的角度来看,这种分离是没有意义的.

While this is not a bug per se, The MathWorks still might be interested in this difference in behavior and poor performance of sym/solve (and the underlying symobj::solvefull) relative to MuPAD's solve. File a bug report if you like. For the life of me I don't understand why they can't better unify these parts of Matlab. The separation makes not sense from the perspective of a user.

这篇关于Matlab解决功能有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆