using symbolic variable with spline interpolations
조회 수: 6 (최근 30일)
이전 댓글 표시
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 -
- How can I get an equation that reproduces my curve and allows me to use symbolic variables as input?
- 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
댓글 수: 0
답변 (1개)
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 < )
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!