source: MML/trunk/machine/SOLEIL/common/toolbox/findX/findX.m @ 17

Last change on this file since 17 was 17, checked in by zhangj, 10 years ago

To have a stable version on the server.

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1%FINDX Single-variable linear level finding ("inverse" INTERP1).
2%   XI = findX(X,Y,YI) estimates the XI values at which the dependent
3%   variables Y reach or cross a specified target level YI (scalar value).
4%   If there are multiple solutions, findX finds all of them.
5%   It may be seen as the "inverse" operation of the MATLAB's function
6%   INTERP1, under 'linear' method.
7%
8%   X is a vector containing a sequence of monotone increasing values of
9%   the independent variable. Y is a vector containing the discrete values
10%   of the dependent variable (underlying function).
11%
12%   [XI,IDEXACT] = findX(X,Y,YI) returns in IDEXACT the indices where the
13%   original values of Y exactly reach the target level YI,
14%   i.e. Y(IDEXACT)=YI, so interpolation was not needed.
15%
16% Antoni J. Canos.
17% Microwave Heating Group, GEA.
18% ITACA, Technical University of Valencia.
19% Valencia (Spain), April 2009
20
21function [XI,IDEXACT] = findX(X,Y,YI)
22
23% Check dimensions of input arrays
24m=length(X);
25r=length(Y);
26
27if ~isvector(X) | ~isvector(Y)
28    error('X and Y must be vectors.');
29end
30
31if (m ~= r)
32    error('Lengths of X and Y vectors must be the same.');
33end
34
35% Initialize outputs
36XI = [];
37IDEXACT = [];
38IDINTERP = [];
39
40% Subtract target level to simplify subsequent code
41Y = Y - YI;
42
43% Find exact values. They can be crossings or "kisses".
44IDEXACT = find(Y==0);
45
46% Find crossings
47IDINTERP = find ( Y(1:end-1) .* Y(2:end) < 0 );
48
49% Calculating XI values and combining
50XI = union(X(IDEXACT),X(IDINTERP) + (X(IDINTERP+1) - X(IDINTERP)) .* Y(IDINTERP) ./ (Y(IDINTERP) - Y(IDINTERP+1)));
51
Note: See TracBrowser for help on using the repository browser.