【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的误差限

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

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

相关推荐
码了三年又三年10 分钟前
【算法】滑动窗口—最小覆盖子串
算法
AIAdvocate10 分钟前
力扣-96.不同的二叉搜索树 题目详解
python·算法·动态规划
说好不能打脸11 分钟前
利用模糊综合评价法进行数值评分计算——算法过程
算法
小周的C语言学习笔记13 分钟前
鹏哥C语言33---循环语句 for
c语言·c++·算法
shylyly_16 分钟前
归并排序
数据结构·算法·归并排序·递归归并排序·非递归归并排序
luthane17 分钟前
python 实现entropy熵算法
python·算法·概率论
X BoHang17 分钟前
洛谷 P4683 [IOI2008] Type Printer
算法
自身就是太阳21 分钟前
Maven的高级特性
java·开发语言·数据库·后端·spring·maven
hakesashou27 分钟前
ruby和python哪个好学
开发语言·python·ruby
林一怂儿32 分钟前
H5 three.js 实现六年级观察物体
开发语言·javascript