using symbolic variable with spline interpolations

26 ビュー (過去 30 日間)
mridul mridul
mridul mridul 2021 年 2 月 27 日
編集済み: Walter Roberson 2021 年 2 月 27 日
I have a program that requires input data as a curve. I find spline curves best represent required input curves, so I draw them in a CAD software and import them as coordinates in matlab. I use interpolation to get the curve but rest of my program uses symbolic variables so I get errors. I have two questions -
  1. How can I get an equation that reproduces my curve and allows me to use symbolic variables as input?
  2. Is there a way I can move points in a matlab GUI that changes my input curve?
r = readmatrix('curve.txt');
x = r(:,1)';
y = r(:,2)';
syms phi;
pp = spline(x, y);
[~, coeffs] = unmkpp(pp);
a = [phi^3 phi^2 phi 1];
desired_function = dot(coeff,a);
the above program gives me 42 curves for 43 points, however in CAD it is a single spline between two points. I would like to get a single equation.
Thank you

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 27 日
編集済み: Walter Roberson 2021 年 2 月 27 日
[~, coeffs] = unmkpp(pp);
Splines are not a single equation in the sense of a single polynomial that works from beginning to end. Splines are piecewise polynomial, and if you want a single equation, it would have to be constructed as piecewise.
The breaks (places each segment is valid) are returned as the first output of unmkpp.
"Polynomial coefficients, returned as an L-by-k matrix with each row coefs(i,:) containing the local coefficients of an order k polynomial on the ith interval, [breaks(i),breaks(i+1)]."
So create a vector
phi>= breaks(1:end-1) & phi<breaks(2:end)
and put those into individual cells, and do your matrix multiplication with phi powers and slice the results by row into cells, interleave the cells, piecewise() of cell expansion to get the final expression.
(In practice you need to repair the last upper bound to <= instead of < )

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by