Convert interpolation function to symbolic
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Luiz Ricardo Almeida
el 10 de Feb. de 2020
Comentada: Bjorn Gustavsson
el 13 de Feb. de 2020
Hello,
I have a Nx2 .dat file which I import to Matlab as a Nx2 matrix. This .dat file is roughly a collection of [x,y] coordinates of a curve.
What I am trying to do is to obtain not only the curve that intepolates those point but also its form in symbolic code.
My code is the following
clc
clear all
%Importing .dat file and converting to a nx2 matrix
f = fopen('GITT_bi1g20.dat');
data = textscan(f, '%f %f');
data = cell2mat(data); % convert to matrix from cell array
fclose(f);
%Comparison between different interpolation functions
%Polynomial
x = data(:,1);
y = data(:,2);
p = polyfit(x,y,9);
y1 = polyval(p,x);
%pchip() - Hermitian
xx = x;
p = pchip(x,y,xx);
figure(1)
hold on
plot(data(:,1),data(:,2),'m')
plot(xx,p,'--black')
hold off
My biggest wish is actually write the pchip() that intepolates the data points as a symbolic function. (So I can do some Calculus stuff with it and other symbolic functions I am using)
Thanks in advance.
0 comentarios
Respuesta aceptada
Bjorn Gustavsson
el 10 de Feb. de 2020
You already get a piecewise polynomial out of pchip. That is a symbolic function - though not on the form expected by the symbolic functions of matlab so not the format you want. Bot look at the form of your final p and you should be able to figure out what to do next.
HTH
4 comentarios
Bjorn Gustavsson
el 13 de Feb. de 2020
Cheers. I thought that since they are polynomials it would be "reasonably" straight-forward to integrate and differentiate - D(a*x^n) = n*a*x^(n-1) etc. I must admit that I spent no time at all thinking about exactly how the polynomials were represented, so it might get tricky in practice. Then on the other hand polynomials are reasonably well suited for numerical integration so you could wihtout much loss turn to that.
Más respuestas (0)
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!