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

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

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

相关推荐
艾莉丝努力练剑38 分钟前
【LeetCode&数据结构】单链表的应用——反转链表问题、链表的中间节点问题详解
c语言·开发语言·数据结构·学习·算法·leetcode·链表
_殊途2 小时前
《Java HashMap底层原理全解析(源码+性能+面试)》
java·数据结构·算法
倔强青铜35 小时前
苦练Python第18天:Python异常处理锦囊
开发语言·python
u_topian5 小时前
【个人笔记】Qt使用的一些易错问题
开发语言·笔记·qt
珊瑚里的鱼6 小时前
LeetCode 692题解 | 前K个高频单词
开发语言·c++·算法·leetcode·职场和发展·学习方法
AI+程序员在路上6 小时前
QTextCodec的功能及其在Qt5及Qt6中的演变
开发语言·c++·qt
xingshanchang6 小时前
Matlab的命令行窗口内容的记录-利用diary记录日志/保存命令窗口输出
开发语言·matlab
Risehuxyc6 小时前
C++卸载了会影响电脑正常使用吗?解析C++运行库的作用与卸载后果
开发语言·c++
AI视觉网奇6 小时前
git 访问 github
运维·开发语言·docker
不知道叫什么呀6 小时前
【C】vector和array的区别
java·c语言·开发语言·aigc