distribution of interpolation points in spline interpolation
조회 수: 2 (최근 30일)
이전 댓글 표시
rng("default") n = 10; x = linspace(1,10,n); xi = linspace(min(x), max(x), 1e3); y = rand(length(x)); pp = csape(x,y); % interpolating spline f ei = eye(length(x)); dfdy = csape(x,ei); % derivative df/dy1i for i=1,...,n dfdy = ppval(dfdy, xi); plot(xi, dfdy');
Consider the above code to compute the derivative of a spline f(y1,...,yn) w.r.t the interpolation values y on equally distributed interpolation points x.
Obviously, the df/dyi, hence d/dx(df/dyi), are fully determined by the spacing between the points (hi = xi1 - xi) and I was wondering whether there is a clever distribution of points to make sure d/dx(df/dyn) is in the same ballpark as the other d/dx(df/dyi) like it is the case for equally distributed points as shown in my question. Any ideas are greatly appreciated!
댓글 수: 2
Torsten
2024년 2월 23일
편집: Torsten
2024년 2월 23일
Obviously, the df/dyi, hence d/dx(df/dyi), are fully determined by the spacing between the points (hi = xi1 - xi) and I was wondering whether there is a clever distribution of points to make sure d/dx(df/dyn) is in the same ballpark as the other d/dx(df/dyi) like it is the case for equally distributed points as shown in my question.
And why do you want this ? To get better performance/convergence of your optimization ?
답변 (1개)
Hassaan
2024년 2월 23일
n = 10;
x_star = 6; % Your threshold value
x = [linspace(1, x_star, n-1), 10]; % Densely pack x-values up to x_star, then jump to last point
xi = linspace(min(x), max(x), 1e3); % Dense x for interpolation and plotting
y = rand(1, length(x)); % Random y-values for demonstration
pp = csape(x, y, 'variational'); % Interpolating spline
dfdy = csape(x, eye(length(x)), 'variational'); % Derivative df/dy
% Evaluate the derivative spline at the dense xi points
dfdy_val = ppval(dfdy, xi);
% Plot the original spline and its derivatives
figure;
subplot(2, 1, 1);
plot(xi, ppval(pp, xi), 'LineWidth', 2);
title('Spline Interpolation of y');
subplot(2, 1, 2);
plot(xi, dfdy_val', 'LineWidth', 2);
title('Derivatives of the Spline w.r.t y');
xlabel('x');
ylabel('df/dy');
legend(arrayfun(@(idx) sprintf('df/dy%d', idx), 1:n, 'UniformOutput', false));
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
댓글 수: 2
Hassaan
2024년 2월 23일
@Hassaan Strategy for Balancing Derivatives Across the Domain
- Adaptive Point Distribution: Instead of linearly distributing points up to ∗x∗ and then making a large jump, consider using an adaptive scheme that gradually changes the density of points. This can be somewhat complex to implement, as it involves dynamically adjusting the spacing based on the behavior of the derivative of the spline. One approach might be to start with a uniform distribution, evaluate the sensitivity (magnitude of the derivative), and then adjust the spacing iteratively.
- Piecewise Polynomial Construction: Instead of using a single spline across the entire domain, consider constructing piecewise polynomials where you have more control over the behavior of each segment. This allows you to ensure that the influence of each control point yi is more uniform across the domain. Each piece can be defined over intervals with more uniform control over the derivative's behavior.
- Weighted Derivative Calculation: When computing the derivative of the spline with respect to each yi, introduce a weighting scheme that accounts for the non-uniform spacing of x points. This involves modifying the objective function to incorporate a weighting factor that balances the influence of points in denser regions against those in sparser regions.
- Optimization-Based Distribution: Formulate the problem of finding the optimal x distribution as an optimization problem itself. The objective could be to minimize the variance in the magnitude of dxd(dyidf) across the domain or to ensure that the derivatives at points ∗xi>x∗ are within a desired range of those at ∗xi<x∗. This is a meta-optimization problem that requires careful formulation.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!