Is there any way to find maximum and/or zeros of a vector?

5 views (last 30 days)
How do I find the max value and zeros of a vector (not a function) when the peak or zero may occur between vector elements?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Apr 2023
Edited: MathWorks Support Team on 13 Apr 2023
There is no direct way to do discrete optimization using the MATLAB Optimization Toolbox.
The best way to solve a system of discrete equations is to design a function that interpolates from the data. For example, if your table has one column of independent values and a second column of dependent values, your function might look like this:
function f = myfun(x)
load mydata.mat
f = interp1(mydata(:,1), mydata(:,2), x);
You might also be able to use a data fitting routine such as POLYFIT or LSQNONLIN to first find coefficients for a model that fits your vector data. You can then use all of the available minimization routines (FSOLVE, FMINSEARCH, FMINUNC, FZERO, LSQNONLIN, etc.) to find zeros and peaks.
Another way is to do this is to create your own code. For example, the popular Newton-Raphson method can be used to solve many problems. A user has written code implementing this method:
Note that MathWorks does not guarantee or warrant the use or content of these submissions. Any questions, issues, or complaints should be directed to the contributing author.
There are also other methods which you can use. For example, finding the smallest tolerance of the absolute (see ABS), followed by checking the sign of the product of two consecutive elements there, will tell if it is a zero for the function. Once that is done, interpolation can be used (INTERP1, for instance) to find out where between those two points.

More Answers (0)

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!