Fzreo matlab
fzero
Root of nonlinear function
Syntax
Description
Examples
Root Starting From One Point
Calculate
by finding the zero of the sine function near
3.
fun = @sin; % function
x0 = 3; % initial point
x = fzero(fun,x0)
x =
3.1416
Root Starting From an Interval
Find the zero of cosine between 1 and 2.
fun = @cos; % function
x0 = [1 2]; % initial interval
x = fzero(fun,x0)
x =
1.5708
Note that
and
differ in sign.
Root of a Function Defined by a File
Find a zero of the function f(x) = x3 – 2x – 5.
First, write a file called f.m.
function y = f(x)
y = x.^3 - 2*x - 5;
Save f.m on your MATLAB® path.
Find the zero of f(x)near 2.
fun = @f; % function
x0 = 2; % initial point
z = fzero(fun,x0)
z =
2.0946
Since f(x) is a polynomial, you canfind the same real zero, and a complex conjugate pair of zeros, usingthe
roots command.
roots([1 0 -2 -5])
ans =
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
Root of Function with Extra Parameter
Find the root of a function that has an extra parameter.
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
Nondefault Options
Plot the solution process by setting some plot functions.
Define the function and initial point.
fun = @(x)sin(cosh(x));
x0 = 1;
Examine the solution process by setting options that include plot functions.
options = optimset('PlotFcns',{@optimplotx,@optimplotfval});
Run fzero including options.
x = fzero(fun,x0,options)
x =
1.8115

Solve Problem Structure
Solve a problem that is defined by a problem structure.
Define a structure that encodes a root-finding problem.
problem.objective = @(x)sin(cosh(x));
problem.x0 = 1;
problem.solver = 'fzero'; % a required part of the structure
problem.options = optimset(@fzero); % default options
Solve the problem.
x = fzero(problem)
x =
1.8115
More Information from Solution
Find the point where exp(-exp(-x)) = x, and display information about the solution process.
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 = intervaliterations: 0
iterations: 5
funcCount: 7
algorithm: 'bisection, interpolation'
message: 'Zero found in the interval [0, 1]'
fval = 0 means fun(x) = 0, as desired.
Related Examples
Input Arguments
fun — Function to solvefunction handle
Function to solve, specified as a handle to a scalar-valuedfunction. fun accepts a scalar
x andreturns a scalar fun(x).
fzero solves fun(x) = 0. To solve an equation ,instead solve
fun(x) = c(x)fun2(x) = fun(x) - c(x) = 0.
To include extra parameters in your function, see the example Root of Function with Extra Parameter andthe section Parameterizing Functions.
Example: @sin
Example: @myFunction
Example: @(x)(x-a)^5 - 3*x + a - 1
Data Types: function_handle
x0 — Initial valuescalar | 2-element vector
Initial value, specified as a real scalar or a 2-element realvector.
Scalar —
fzerobegins atx0andtries to locate a point
x1wherefun(x1)hasthe opposite sign offun(x0). Then
fzeroiterativelyshrinks the interval wherefunchanges sign toreach a solution.2-element vector —
fzerochecksthatfun(x0(1))andhaveopposite signs, and errors if they do not. It then iteratively shrinksthe interval where
fun(x0(2))
funchanges sign to reach asolution. An intervalx0must be finite; it cannotcontain ±Inf.
|
Tip Calling |
Example: 3
Example: [2,17]
Data Types: double
options — Options for solution processstructure, typically
created using optimset
Options for solution process, specified as a structure. Createor modify the structure using
optionsoptimset. fzero usesthese options structure fields.
|
|
Level of display:
|
|
|
Check whether objective functionvalues are valid.
|
|
|
Specify one or more user-definedfunctions that an optimization function calls at each iteration, eitheras a function handle or as a cell array of function handles. The defaultis none ( |
|
|
Plot various measures of progresswhile the algorithm executes. Select from predefined plots or writeyour own. Pass a function handle or a cell array of function handles.The default is none (
For information on writing a custom plot function,see Plot Functions. |
|
|
Termination tolerance on |
Example: options = optimset('FunValCheck','on')
Data Types: struct
problem — Root-finding problemstructure
Root-finding problem, specified as a structure with all of thefollowing fields.
|
|
Objective function |
|
|
Initial point for x,real scalar or 2-element vector |
|
|
'fzero' |
|
|
Options structure, typically createdusing optimset |
For an example, see Solve Problem Structure.
Data Types: struct
Output Arguments
x — Location of root or sign changereal scalar
Location of root or sign change, returned as a scalar.
fval — Function value at
xreal scalar
Function value at x, returned as a scalar.
exitflag — Integer encoding the exit conditioninteger
Integer encoding the exit condition, meaning the reason fsolve stoppedits iterations.
|
|
Function converged to a solution |
|
|
Algorithm was terminated by the output function or plotfunction. |
|
|
|
-4 |
Complex function value was encountered while searchingfor an interval containing a sign change. |
-5 |
Algorithm might have converged to a singular point. |
-6 |
|
output — Information about root-finding processstructure
Information about root-finding process, returned as a structure.The fields of the structure are:
intervaliterations |
Number of iterations taken to find an interval containinga root |
iterations |
Number of zero-finding iterations |
funcCount |
Number of function evaluations |
algorithm |
|
message |
Exit message |
More About
References
[1] Brent, R., Algorithms forMinimization Without Derivatives, Prentice-Hall, 1973.
[2] Forsythe, G. E., M. A. Malcolm, and C.B. Moler, Computer Methods for Mathematical Computations,Prentice-Hall, 1976.
Fzreo matlab的更多相关文章
- Matlab 绘制三维立体图(以地质异常体为例)
前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...
- Matlab slice方法和包络法绘制三维立体图
前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...
- Matlab 高斯_拉普拉斯滤波器处理医学图像
前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...
- MATLAB中绘制质点轨迹动图并保存成GIF
工作需要在MATLAB中绘制质点轨迹并保存成GIF以便展示. 绘制质点轨迹动图可用comet和comet3命令,使用例子如下: t = 0:.01:2*pi;x = cos(2*t).*(cos(t) ...
- linux下配置matlab运行环境(MCR)
在安装好的matlab下有MCR(MatlabCompilerRuntime)在matlab2011/toolbox/compiler/deploy/glnxa64下找到MCRInstaller.zi ...
- EMD分析 Matlab 精华总结 附开源工具箱(全)
前言: 本贴写于2016年12与15日,UK.最近在学习EMD(Empirical Mode Decomposition)和HHT(Hilbert-Huang Transform)多分辨信号处理,FQ ...
- Atitit MATLAB 图像处理 经典书籍attilax总结
Atitit MATLAB 图像处理 经典书籍attilax总结 1.1. MATLAB数字图像处理1 1.2. <MATLAB实用教程(第二版)>((美)穆尔 著)[简介_书评_在线阅读 ...
- Atitit MATLAB 图像处理attilax总结
Atitit MATLAB 图像处理attilax总结 1.1. 下载 Matlab7.0官方下载_Matlab2012 v7.0 官方简体中文版-办公软件-系统大全.html1 1.2. Matla ...
- Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结
Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结 1.1. 边缘检测的基本方法Canny最常用了1 1.2. 编写matlab边缘检测代码, ...
随机推荐
- Vue实现懒加载的基本思路
懒加载是前端开发者的基本功之一.实现懒加载肯定是要直接操作DOM的,这个没得跑,但我们可以想办法让流程尽可能优雅些. 基本结构 父组件是列表容器,子组件是列表中的项,如卡片.帖子等,承载图片的DOM对 ...
- Canal学习笔记(服务端)
canal服务端 canal服务端有两种运行模式,一种单机模式,一种HA运行模式(zk保证) 单机模式:同步的binlog节点信息保存在本地(/conf/{自定义分区文件夹}/),meta.dat H ...
- 使用idea配置tomcat将web项目跑起来
链接:https://www.cnblogs.com/avivaye/p/6437555.html
- python zeros用法实例
编程就是踩坑的过程.今天又踩了一个坑,做个积累吧. 在给数组赋初始值的时候,经常会用到0数组,而Python中,我们使用zero()函数来实现.在默认的情况下,zeros创建的数组元素类型是浮点型的, ...
- 远程计算机或设备将不接受连接(电脑能连接网络、QQ能登陆、浏览器无法使用)
第一种方法 1.win+r 2.输入regedit,打开注册表 3.查找Internet Settings(在HKEY_CURRENT_USER\Software\Microsoft\Windows\ ...
- Android--解析XML之DOM
前言 前面已经介绍了Android平台下两种解析XML的方法,SAX和PULL,这两个均为事件驱动,以流的形式解析XML文档.现在介绍一种新的方式DOM方式解析XML. DOM是一种用于XML文档对象 ...
- Spring Boot Jersey使用示例
前言 本文将学习如何使用Spring Boot和Jersey框架,去配置和创建JAX-RS 2.0 REST API接口: 这个示例应用使用的是Jersey的Servlet容器去部署REST API接 ...
- Java集合:整体结构
一.Java中集合 Java中集合类是Java编程中使用最频繁.最方便的类.集合类作为容器类可以存储任何类型的数据,当然也可以结合泛型存储指定的类型(不过泛型仅仅在编译期有效,运行时是会被擦除的).集 ...
- leetcode — rotate-list
/** * Source : https://oj.leetcode.com/problems/rotate-list/ * * * Given a list, rotate the list to ...
- 手把手在Ubuntu上面安装Docker
一.环境准备 1.Ubuntu64位系统(目前docker仅支持64位系统) 2.官方支持的Ubuntu版本(1)Ubuntu Trusty 14.04(LTS)(2)Ubuntu Precise 1 ...