Be the first to rate this file! 1 Download (last 30 days) File Size: 5.17 KB File ID: #10907
image thumbnail

Seekpeaks

by Per Sundqvist

 

28 Apr 2006 (Updated 28 Apr 2006)

find maxima of an arbitrary function

| Watch this File

File Information
Description

[xm,ym,xx,yy]=Seekpeaks(fun,x,y,y_tol,Nsteps,varargin)
Searches the maxima of the function 'fun', which is an object such as produced by inline or by a m-function. y=fun(x,P1,P2,...), where P1, P2,...are additional parameters used in the function 'fun' and are given in 'varargin' in Seekpeaks as p1,p2,... (see example below)
Note: use 'fun' for m-function and (just) fun for inline function

     The INPUT x and y (=fun(x)) are the samples used to locate the maxima and the program will refine iterativeley around the local maxima to find the exact maxima. y_tol gives the relative stop criteria for stopping the maxima search and Nsteps is a number to terminate the session in case it takes long time to find the maxima. Default are 1e-6 and 50 and will be used in case [],[] are used as arguments in the function.

     The OUTPUT xm gives the positions of the maxima and ym the corresponding values (vectors). xx and yy gives the union of all values that are found during the refinement including the input sample x and y (it is useful for plot-purposes).

%%% Example:

define a function fun(x) with an additional parameter s
fun1=inline('s^2*(1./(s^2+(x-1).^2)+1./(s^2+(x-2).^2))','x','s')
% calculate a rough sample (x,y) of the function
x=linspace(0,3,20);
s=0.001; %parameter
y=fun1(x,s);
% Seek the peaks of the function fun1
[xm,ym,xx,yy]=Seekpeaks(fun1,x,y,[],[],s);
xm
plot(xx,yy,x,y,'.');

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
approximation Per Sundqvist 22 Oct 2008 08:23:39
interpolation Per Sundqvist 22 Oct 2008 08:23:39
maxima Per Sundqvist 22 Oct 2008 08:23:39
peaks Per Sundqvist 22 Oct 2008 08:23:39
search Per Sundqvist 22 Oct 2008 08:23:39
mathematics Per Sundqvist 22 Oct 2008 08:23:39

Contact us at files@mathworks.com