【matlab基础知识代码】(十七)一般非线性方程的数值解方法

复制代码
function y=myfun(x)
y=[x(1)*x(1)+x(2)*x(2)-1;0.75*x(1)^3-x(2)+0.9];
>> OPT=optimset; OPT.LargeScale='off'; [x,Y,c,d]=fsolve(f,[1; 2],OPT),

Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>

x =    方程的解

    0.3570
    0.9341


Y =    方程的误差

   1.0e-09 *

    0.1215
    0.0964


c =   标志位>0,求解成功

     1


d =    中间信息

  包含以下字段的 struct:

       iterations: 6   迭代次数
        funcCount: 21  调用函数
        algorithm: 'trust-region-dogleg'
    firstorderopt: 1.3061e-10
          message: '↵Equation solved.↵↵fsolve completed because the vector of function values is near zero↵as measured by the value of the function tolerance, and↵the problem appears regular as measured by the gradient.↵↵<stopping criteria details>↵↵Equation solved. The sum of squared function values, r = 2.406007e-20, is less than↵sqrt(options.FunctionTolerance) = 1.000000e-03. The relative norm of the gradient of r,↵1.306113e-10, is less than options.OptimalityTolerance = 1.000000e-06.↵↵'
Matlab 复制代码
>> [x,Y,c,d]=fsolve(f,[-1,0]',OPT); x, norm(Y), kk=d.funcCount,

Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>

x =

   -0.9817
    0.1904


ans =

   7.2257e-11


kk =

    15

误差限TolX 也就是X的误差限

重新设置相关精度的控制变量

精度高得多得多,因为把这个解代回到原始的方程里去,误差是一个非常接近零的数。我们可以修改控制变量,最后能得到双精度意义下的最好的结果

相关推荐
oioihoii3 分钟前
C++23 中的 ranges::fold_left:范围折叠算法
算法·c++23
小乖兽技术17 分钟前
在 .NET 8 开发的WinForms 程序中展示程序版本号的几种方式
开发语言·c#·.net
zyhomepage27 分钟前
科技的成就(六十八)
开发语言·人工智能·科技·算法·内容运营
slandarer27 分钟前
MATLAB | R2025a 更新了哪些有趣的东西?
开发语言·matlab
瑞雪兆丰年兮29 分钟前
数学实验(Matlab编程基础)
开发语言·算法·matlab·数学实验
✿ ༺ ོIT技术༻32 分钟前
笔试强训:Day5
c++·算法
Hygge-star39 分钟前
【数据结构】二分查找-LeftRightmost
java·数据结构·算法
代码小将44 分钟前
Leetcode76覆盖最小子串
笔记·学习·算法
努力的小帅1 小时前
C++_STL_map与set
开发语言·数据结构·c++·学习·leetcode·刷题
yezipi耶不耶1 小时前
Rust入门之高级Trait
开发语言·后端·rust