interp1 fails to interpolate correctly

I have a set of input data which the function interp1 is incorrectly interpolating.
For a statement Vq = interp1(X,V,Xq), I have
X =
-0.0124393747904463
0.0134396235257952
0.0344412390769423
0.0850313641677704
0.0850004675375172
0.126329531171773
V =
-4
-2
0
2
4
6
Clq =
0.0772456107479591
The result interp1 gives me is Vq = 3.3864734865877. This is clearly wrong, but may be related to the face that between V = 4 and V =6, X is not monotonically increasing/decreasing. Can someone help me understand why this is failing?

 Risposta accettata

Matt J
Matt J il 17 Nov 2019
Modificato: Matt J il 17 Nov 2019
X needs to be montonically increasing (or interp1 will pre-sort the data so that it is).

Più risposte (1)

Vladimir Sovkov
Vladimir Sovkov il 18 Nov 2019
Why do you consider it is wrong? In the plot (see the attachment) this result looks quite reasonable.

5 Commenti

My Clq is between the 3rd and 4th element of X. Thus, Vq should be between the 3rd and 4th element of V (0 to 2). The Vq calculated is clearly not in that range. I've looked at your plot, and I don't understand what happened. Why is the V=2 point removed and shifted over to make a line with V=6?
Do you mean that your dependence really goes from the third to the fourth point and then from the fourth point to the fifth one? As the fifth X is smaller than the fourth one, it makes the dependence to be double-valued between the fourth and fifth points. Matlab's interp1 deals with functions alone, i.e. with the one-to-one mappings, no double-valued dependences are allowed. Consequently, it sorts your data in the accending order of X switching your fourth and fifth points in order to make it actual function. In the sorted version, your Clq is between the 3rd and 5th (new 4th) points. This interp1 is unapplicable to double-valued dependencies and, if this is really the case, you should find another way to interpolate it. Maybe, you can just drop out the 5th and 6th points....
Your point is taken, and technically there is no generic way to interpolate a double valued function. However, I am nethertheless tasked with doing precisely that. I'm trying to find the angle of attack of an aircraft that, for some inexplicable reason, is generating less lift when the nose is raised form 2 to 4 degrees of pitch in this case. Maybe I'll make a polynomial fit and root solve for the angle....
polynomial fits cannot solve double-valued functions.
Sometimes you should use a function of two variables instead.
Sometimes you can rewrite as a parameteric function.
Sometimes you just need to segment to decide which function is in control. For example hysterisis has to be handled as a pair of functions, not by trying to fit one single function.
Maybe, switching roles of X and V can help, e.g.:
VV=fzero(@(z)(interp1(V,X,z)-Clq),1)
VV=1.69220264208349

Accedi per commentare.

Categorie

Scopri di più su Interpolation of 2-D Selections in 3-D Grids in Centro assistenza e File Exchange

Prodotti

Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by