本文介绍了是否可以在Matlab中获得任意方程的多个解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个函数f = @(x) myfun(x);

我可以使用 fzero 来获得最接近的解决方案给定的x0,但是我可以在特定区域获得所有解决方案,例如:-5 < x < 5?

I can use fzero to get the solution closest to a given x0, but can I get all solutions in a specific area, for instance: -5 < x < 5?

即是否有可能得到类似于 roots 的结果的解决方案,但对于非多项式?

I.e.Is it possible to get a solution similar to the result of roots, but for non-polynomials?

推荐答案

是的,可以.

在文件交换上有一个很好的提交,您可以执行此操作.它通过用Chebychev多项式逼近曲线,然后找到该多项式的所有实根来工作.

There's a nice submission on the file exchange that allows you to do exactly that. It works by approximating your curve by a Chebychev polynomial, and then finding all real roots of that polynomial.

如果您愿意,可以将这些根的估计值用作fzero的初始值,但是通常(至少对于平滑和行为良好的曲线而言),已经可以通过使用高阶Chebychev来满足精度要求.近似.

If you want you can use these estimates for the roots as initial values for fzero, but often (at least for smooth and otherwise well-behaved curves) the accuracy demands can already be met by using a higher-order Chebychev approximation.

在您的示例中,仅使用18个函数求值(我对该文件进行了稍微修改,但是本质是相同的):

For your example, using only 18 function evaluations (I have a slightly modified version of the file, but the essence is the same):

>> f = @(A) 17.7*sin(A).*cos(A)+87*sin(A).^2-9.65*cos(A)-47*sin(A);
>> R = FindRealRoots(f, -5,5, 17)
R =
  -3.709993256346244
  -3.345207732130925
  -0.201929737187637
   0.572382702285053
   2.573423209113534
   2.937157987217741

>> R2 = R;
>> funcCount = 0;
>> for ii = 1:numel(R)
        [R2(ii), ~,~, output]  = fzero(f,R2(ii));
        funcCount = funcCount + output.funcCount;
   end
>> max(abs(R2(:)-R(:)))
ans =
    8.564253235401331e-004
>> funcCount
ans =
    46

例如,每万个改进中只有8个部件,而不少于46个附加功能评估.

e.g., there is only 8 parts per ten thousand improvement for no less than 46 additional function evaluations.

这篇关于是否可以在Matlab中获得任意方程的多个解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 01:49