leftstats.blogg.se

Matlab interp1 for extrapolation to get x for given y
Matlab interp1 for extrapolation to get x for given y











matlab interp1 for extrapolation to get x for given y

handling problematic inputĪt the moment, there are no error checks. Checking max and min values feels like an overcomplication. After all, extrapolation just means using the same slope as the first and last interpolation steps. The case for extrapolation could be included in the for loop without being explicitly coded.

MATLAB INTERP1 FOR EXTRAPOLATION TO GET X FOR GIVEN Y CODE

I feel like this code could be simplified further. Here's how this could look like: double Interpolation::linear What is alpha? varSurf? detail_sensativity? And again, given there are many interpolation methods, what is Interp1? With your code alone, that would have been much harder.

matlab interp1 for extrapolation to get x for given y

I know what an interpolation function should be doing and with the clue that you are trying to duplicate griddedInterpolant(X,V,method) I knew what's going on. It's part of a bigger problem that's related to the former paragraph: you use domain specific names which are very cryptic to anybody outside your field. If you are a real C programmer, you'd shove all the condition of if (detail_sensativity >= alpha & detail_sensativity & alpha, used size_t i to top and used it for both cases.moved intreaxtrapolation block to the end.else // we need linear interpolation/extrapolation.

matlab interp1 for extrapolation to get x for given y

(only last else part of your code shown) // !!!!!!!!!! indicates lines of significant change. Here's an untested implementation of that. All code beforehand basically just figures out the right index i to use, then perform the code block. To simplify your code, move the block to the end. duplicated codeįor the code, that means the following block is a duplicate: //y = y0 + (y1-y0)*(x-x0)/(x1-x0) ĭouble res = y0 + (y1 - y0)*(x - x0) / (x1 - x0) That's somewhat plausible I'd say, because no matter if you are interpolating or extrapolating, you are still applying the formula for a line and that's the same whether you are between two points that define the line or outside of them. $$\frac$$Īs can be seen in W\$\alpha \$ of the first and W\$\alpha \$ of the second (as the alternate forms are neatly in the same location, you can toggle between both tabs)Įven without the additional brackets around ((x - x0) / (x1 - x0)), it would still be the same thing. If (detail_sensativity >= min & detail_sensativity = alpha & detail_sensativity = alpha.end)ĭouble res = y0 + ((x - x0) / (x1 - x0)) * (y1 - y0) Std::vector::const_iterator it = std::find(alpha.begin(), alpha.end(), detail_sensativity) Įlse // we need linear interpolation/extrapolation.ĭouble max = *std::max_element(alpha.begin(), alpha.end()) ĭouble min = *std::min_element(alpha.begin(), alpha.end()) in case the interoplation point alraedy exists in the array double Model::Interp1(const std::vector& alpha, const std::vector& varSurf, double detail_sensativity) Please review the extrapolation part as I'm not quite sure about it and comment about the algorithm correctness. GriddedInterpolant(X,V,method) is doing inside Interp1.













Matlab interp1 for extrapolation to get x for given y