natural cubic spline interpolation of y-values: how to get derivative of the spline wrt the y-values?

16 vues (au cours des 30 derniers jours)
Given a data set with support points x_1,...,x_n and corresponding y-values y_1,...,y_n.
My objective is to create a cubic spline f (with natural boundary conditions) that passes through the y_values. There are, of course, plenty of functions for doing this.
However, for a parameter identification procedure, I have to compute the derivative of the spline f with respect to the y-values -- at arbitrary points within [x1, x_n].
Is there an easy way using built-in functions of Matlab to compute the sensitivities?
  2 commentaires
SA-W le 8 Mar 2023
Because the values y_1,...,y_n are the parameters of my optimization. My objective is to optimize the values y_1,...,y_n and interpolate between them with cubic splines. Is that clear?

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 8 Mar 2023
Modifié(e) : Bruno Luong le 8 Mar 2023
The derivative f wrt to y_i is the spline interpolate b_i := (0,0,...,1,0...) where 1 is at ith position, since the spline is linear to y values.
Replace spline command with your function that computes natural spline pp form
f = 1×500
0.8578 0.8215 0.7861 0.7516 0.7180 0.6852 0.6533 0.6223 0.5920 0.5627 0.5341 0.5063 0.4794 0.4532 0.4278 0.4032 0.3794 0.3563 0.3340 0.3124 0.2915 0.2714 0.2519 0.2332 0.2152 0.1978 0.1812 0.1652 0.1498 0.1351
plot(x,y,'or',xi,f,'b') %
dfdy=ppval(yd,xi); % dfdy(i,j) is the derivative of f(xi(j)) with respect to y(i))
  17 commentaires

Connectez-vous pour commenter.

Plus de réponses (2)

Bruno Luong
Bruno Luong le 8 Mar 2023
Modifié(e) : Bruno Luong le 8 Mar 2023
you can find my function that compute the derivative of a piecewise polynomiall function (pp), inclusing pp form of the spline functions. This function returns the pp form of the derivative, so you can evaluate using MATLAB ppval.
function ppd = ppder(pp)
ppd = pp;
coefs = ppd.coefs;
n = size(coefs,2);
ppd.coefs = coefs(:,1:n-1).*(n-1:-1:1);
ppd.order = ppd.order-1;
  4 commentaires
Bruno Luong
Bruno Luong le 8 Mar 2023
Modifié(e) : Bruno Luong le 8 Mar 2023
See my answer below, but
"the result should be a single number"
No the result is a scalar function. If we take f at a given point x then it is a scalar.
"...and not a vector b_i := (0,0,...,1,0...)."
I did not tell the derivative is b, the derivative is the spline interpolating b
"why is a cubic spline linear to y values?"
You clearly missunderstand and male confusion betwen being linear and being a lilnear function

Connectez-vous pour commenter.

Torsten le 8 Mar 2023
Déplacé(e) : Torsten le 8 Mar 2023
Why do you want to compute the sensitivities manually ?
Usually, the fitting software computes them using a finite-difference approximation, i.e. by calling your function with
getting back
f_j(y_1,...,y_i,...,y_n) and f_j(y_1,...,y_i+h,...,y_n)
and approximating
df_j/dy_i = (f_j(y_1,...,y_i+h,...,y_n)-f_j(y_1,...,y_i,...,y_n))/h
And this would also be my suggestion on how to do it manually if it is really needed.

Community Treasure Hunt

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

Start Hunting!

Translated by