|
|
玩篮球的手电筒 · Solved: Writing ...· 7 月前 · |
|
|
文雅的炒粉 · 每五秒执行一次的corn表达式 - CSDN文库· 1 年前 · |
|
|
忐忑的卤蛋 · Spring Boot 零基礎入門 ...· 1 年前 · |
|
|
强健的沙发 · [已解决]批处理如何删除文件到回收站 - ...· 2 年前 · |
|
|
冷静的日记本 · 理解 NumPy - NumPy 中文文档· 2 年前 · |
非线性函数的根
通过求正弦函数在
3
附近的零点计算
。
fun = @sin; % function x0 = 3; % initial point x = fzero(fun,x0)
x = 3.1416
求余弦函数在
1
和
2
之间的零点。
fun = @cos; % function x0 = [1 2]; % initial interval x = fzero(fun,x0)
x = 1.5708
请注意, 和 的符号不同。
求函数 f(x) = x 3 – 2x – 5. 的零值
首先,编写一个名为
f.m
的文件。
function y = f(x)
y = x.^3 - 2*x - 5;
将
f.m
保存到 MATLAB
®
路径中。
求 f(x) 在
2
附近的零点。
fun = @f; % function x0 = 2; % initial point z = fzero(fun,x0)
z =
2.0946
因为
f(x)
是一个多项式,所以可以使用
roots
命令求出相同的实数零点和一对复共轭零点。
roots([1 0 -2 -5])
ans = 2.0946 -1.0473 + 1.1359i -1.0473 - 1.1359i
求具有额外参数的函数的根。
myfun = @(x,c) cos(c*x); % parameterized function c = 2; % parameter fun = @(x) myfun(x,c); % function of x alone x = fzero(fun,0.1)
x = 0.7854
通过设置一些绘图函数绘制求解过程。
定义函数和初始点。
fun = @(x)sin(cosh(x)); x0 = 1;
通过设置包括绘图函数的选项检查求解过程。
options = optimset('PlotFcns',{@optimplotx,@optimplotfval});
运行
fzero
,且含带
options
参数。
x = fzero(fun,x0,options)
x = 1.8115
对问题结构体定义的问题求解。
定义对求根问题编码的结构体。
problem.objective = @(x)sin(cosh(x)); problem.x0 = 1; problem.solver = 'fzero'; % a required part of the structure problem.options = optimset(@fzero); % default options
求解。
x = fzero(problem)
x = 1.8115
求出
exp(-exp(-x)) = x
处的点,并显示有关求解过程的信息。
fun = @(x) exp(-exp(-x)) - x; % function x0 = [0 1]; % initial interval options = optimset('Display','iter'); % show iterations [x fval exitflag output] = fzero(fun,x0,options)
Func-count x f(x) Procedure
2 1 -0.307799 initial
3 0.544459 0.0153522 interpolation
4 0.566101 0.00070708 interpolation
5 0.567143 -1.40255e-08 interpolation
6 0.567143 1.50013e-12 interpolation
7 0.567143 0 interpolation
Zero found in the interval [0, 1]
x = 0.5671
fval = 0
exitflag = 1
output = struct with fields:
intervaliterations: 0
iterations: 5
funcCount: 7
algorithm: 'bisection, interpolation'
message: 'Zero found in the interval [0, 1]'
正如所期望的那样,
fval
= 0 表示
fun(x) = 0
。
fun
—
要求解的函数
要求解的函数,指定为标量值函数的句柄或此类函数的名称。
fun
接受标量
x
并返回标量
fun(x)
。
fzero
对
fun(x) = 0
求解。要对方程
fun(x) = c(x)
求解,请改为对
fun2(x) = fun(x) - c(x) = 0
求解。
要在函数中包括额外参数,请参阅示例 具有额外参数的函数的根 和 参数化函数 部分。
示例:
'sin'
示例:
@myFunction
示例:
@(x)(x-a)^5 - 3*x + a - 1
数据类型:
char
|
function_handle
|
string
x0
—
初始值
初始值,指定为实数标量或二元素实数向量。
标量 -
fzero
从
x0
开始并尝试找到
fun(x1)
具有相反符号
fun(x0)
的点
x1
。随后
fzero
迭代收缩
fun
变号的区间以得到一个解。
二元素向量 -
fzero
检查
fun(x0(1))
和
fun(x0(2))
的符号是否相反,如果不相反,则返回错误。它随后迭代收缩
fun
变号的区间以得到一个解。区间
x0
必须是有限的;它不能包含 ±
Inf
。
提示
用区间(含有两个元素的
x0
)调用
fzero
通常比用标量
x0
调用速度更快。
示例: 3
示例: [2,17]
数据类型:
double
options
—
求解过程的选项
optimset
创建的结构体
求解过程的选项,指定为结构体。使用
optimset
创建或修改
options
结构体。
fzero
使用下列
options
结构体字段。
|
|
显示级别:
|
|
|
检查目标函数值是否有效。
|
|
|
以函数句柄或函数句柄的元胞数组的形式来指定优化函数在每次迭代时调用的一个或多个用户定义函数。默认值是“无”(
|
|
|
绘制算法执行过程中的各个进度测量值。从预定义绘图中选择,或者自行编写。传递函数句柄或函数句柄的元胞数组。默认值是“无”(
有关编写自定义绘图函数的信息,请参阅 优化求解器绘制函数 。 |
|
|
关于正标量
|
示例:
options = optimset('FunValCheck','on')
数据类型:
struct
x
— 根或变号位置
根或变号位置,以标量形式返回。
fval
—
x
处的函数值
x
处的函数值,以标量形式返回。
exitflag
— 对退出条件编码的整数
对退出条件编码的整数,表示
fzero
停止其迭代的原因。
|
|
函数收敛于解
|
|
|
算法由输出函数或绘图函数终止。 |
|
|
在搜索含有变号的区间时遇到
|
-4
|
在搜索含有变号的区间时遇到复数函数值。 |
-5
|
算法可能收敛于一个奇异点。 |
-6
|
|
output
— 有关求根过程的信息
有关求根过程的信息,以结构体形式返回。结构体字段有:
intervaliterations
|
求包含根的区间所采取的迭代次数 |
iterations
|
求零点迭代次数 |
funcCount
|
函数计算次数 |
algorithm
|
|
message
|
退出消息 |
fzero
命令是一个函数文件。此算法由 T. Dekker 创建,它结合使用了对分法、正割法和逆二次插值方法。
[1]
中给出了 Algol 60 版及一些改进。
[2]
中给出了
fzero
所基于的 Fortran 版本。
优化
实时编辑器任务为
fzero
提供可视化界面。
[1] Brent, R., Algorithms for Minimization Without Derivatives, Prentice-Hall, 1973.
[2] Forsythe, G. E., M. A. Malcolm, and C. B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, 1976.
对于 C/C++ 代码生成:
fun
输入参数必须是函数句柄,不能是结构体和字符向量。
fzero
忽略除
TolX
和
FunValCheck
之外的所有选项。
fzero
不支持第四个输出参数, 即输出结构体。
backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™
ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅 在基于线程的环境中运行 MATLAB 函数 。
在 R2006a 之前推出
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
MathWorks
Accelerating the pace of engineering and science
MathWorks is the leading developer of mathematical computing software for engineers and scientists.
|
|
文雅的炒粉 · 每五秒执行一次的corn表达式 - CSDN文库 1 年前 |
|
|
强健的沙发 · [已解决]批处理如何删除文件到回收站 - BAT求助&讨论 - 批处理之家 BAT,CMD,批处理,PowerShell,VBS,DOS - Powered by Discuz! 2 年前 |
|
|
冷静的日记本 · 理解 NumPy - NumPy 中文文档 2 年前 |