![]() Rather than use her actual code, which is rather complicated and domain-specific, let’s take a look at a highly simplified version of her problem. Would it be possible to use the NAG toolbox for MATLAB (which hooks into NAG’s superfast Fortran library) to get her results faster she wondered? Between the two of us and the NAG technical support team we eventually discovered that the answer was a very definite yes. ![]() Recently I had an email from someone who had profiled her MATLAB code and had found that it was spending a lot of time in the interp1function. ![]() Often you can get very big speedups in return for only a modest amount of work and as a bonus you get to keep the use of both of your eyes. I have found that a MUCH better course of action is to profile the code, find out where the slow bit is and then do what you can with that. Telling such a person that they should throw their painstakingly put-together piece of code away and learn a considerably more difficult language in order to rewrite the whole thing is unhelpful at best and likely to result in the loss of an eye at worst. I have no doubt that some of you are thinking that the correct answer is something like ‘ completely rewrite it in Fortran or C‘ and if you are then I can only assume that you have never been face to face with a harassed, sleep-deprived researcher who has been sleeping in the lab for 7 days straight in order to get some results prepared for an upcoming conference. "NCM", Numerical Computing with MATLAB, has more mathematical details.I often get sent a piece of code written in something like MATLAB or Mathematica and get asked ‘ how can I make this faster?‘. The v5 cubic is the black curve between spline and pchip.Ī extensive collection of tools for curve and surface fitting, by splines and many other functions, is available in the Curve Fitting Toolbox. Here is our example data, modified slightly to exaggerate behavior, and interpgui modified to include the 'v5cubic' option of interp1. Because the abscissa are equally spaced, the v5 cubic can be evaluated quickly by a convolution operation. The resulting piecewise cubic does not have a continuous second derivative and it does not always preserve shape. I'll tell you later where the coefficients of the cubics come from. These functions are formed by adding cubic terms that vanish at the end points to the linear interpolatant. We have the y-values at the knots, so in order to get a particular PCHIP, we have to somehow specify the values of the derivative, y', at the knots.Ĭonsider these two cubic polynomials in $x$ on the interval $1 \le x \le 2$. ![]() Just as two points determine a linear function, two points and two given slopes determine a cubic. Since we want the function to go through the data points, that is interpolate the data, and since two points determine a line, the plip function is unique.Ī PCHIP, a Piecewise Cubic Hermite Interpolating Polynomial, is any piecewise cubic polynomial that interpolates the given data, AND has specified derivatives at the interpolation points. There is a different linear function between each pair of points. So I added the title plip because this is a graph of the piecewise linear interpolating polynomial. With line type '-o', the MATLAB plot command plots six 'o's at the six data points and draws straight lines between the points. Here is the data that I will use in this post. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |