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

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

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

相关推荐
踏浪无痕11 分钟前
周末拆解:QLExpress 如何做到不编译就能执行?
后端·算法·架构
一个不知名程序员www13 分钟前
算法学习入门--- 树(C++)
c++·算法
毕设源码-朱学姐14 分钟前
【开题答辩全过程】以 基于Java的人体骨骼健康知识普及系统为例,包含答辩的问题和答案
java·开发语言
lly20240618 分钟前
Julia 函数
开发语言
sheji341620 分钟前
【开题答辩全过程】以 基于JAVA的社团管理系统为例,包含答辩的问题和答案
java·开发语言
如竟没有火炬24 分钟前
四数相加贰——哈希表
数据结构·python·算法·leetcode·散列表
周杰伦_Jay27 分钟前
【GOFrame】模块化框架与生产级实践
开发语言·gitlab·github
背心2块钱包邮38 分钟前
第9节——部分分式积分(Partial Fraction Decomposition)
人工智能·python·算法·机器学习·matplotlib
Simon席玉39 分钟前
C++的命名重整
开发语言·c++·华为·harmonyos·arkts
仰泳的熊猫39 分钟前
1148 Werewolf - Simple Version
数据结构·c++·算法·pat考试