Wondering if my spline is any good
Honestly, I just want to know what people think of some data fitting I’ve been doing. Simply given two sets of points (xc,thiscp) and (xc1,thiscp1), I’ve managed to come up with the following piece of code:
xclip = xc(~isnan(xc));
[vals Iclip]=unique(xclip,’first’);
%
xcnew = unique(xclip);
cs = pchip(xcnew,thiscp(Iclip));
for n = 1:length(cs.coefs(:,1))
fun = @(x) cs.coefs(n,1)*(x-cs.breaks(n)).^3+cs.coefs(n,2)*(x-cs.breaks(n)).^2+cs.coefs(n,3)*(x-cs.breaks(n))+cs.coefs(n,4);
int = integral(fun,cs.breaks(n),cs.breaks(n+1));
int2(n)=int;
end
xclip1 = xc1(~isnan(xc1));
[vals Iclip1]=unique(xclip1,’first’);
xcnew1 = unique(xclip1);
cs2 = pchip(xcnew1,thiscp1(Iclip1));
for n = 1:length(cs2.coefs(:,1))
fun1 = @(x) cs2.coefs(n,1)*(x-cs2.breaks(n)).^3+cs2.coefs(n,2)*(x-cs2.breaks(n)).^2+cs2.coefs(n,3)*(x-cs2.breaks(n))+cs2.coefs(n,4);
int1 = integral(fun1,cs2.breaks(n),cs2.breaks(n+1));
int3(n)=int1;
end
intall = abs(sum(int2,’all’)-sum(int3,’all’))
This is one of the several methods I’ve devised to evaluate the area between two curves drawn by each set of data points. Currently, I am experiencing some inconsistencies when my data points are greatly vertically spaced – I am wondering if there is any way to remedy this. I am also curious as to how accurate this method is, and need some more experienced minds to comment. Thanks!Honestly, I just want to know what people think of some data fitting I’ve been doing. Simply given two sets of points (xc,thiscp) and (xc1,thiscp1), I’ve managed to come up with the following piece of code:
xclip = xc(~isnan(xc));
[vals Iclip]=unique(xclip,’first’);
%
xcnew = unique(xclip);
cs = pchip(xcnew,thiscp(Iclip));
for n = 1:length(cs.coefs(:,1))
fun = @(x) cs.coefs(n,1)*(x-cs.breaks(n)).^3+cs.coefs(n,2)*(x-cs.breaks(n)).^2+cs.coefs(n,3)*(x-cs.breaks(n))+cs.coefs(n,4);
int = integral(fun,cs.breaks(n),cs.breaks(n+1));
int2(n)=int;
end
xclip1 = xc1(~isnan(xc1));
[vals Iclip1]=unique(xclip1,’first’);
xcnew1 = unique(xclip1);
cs2 = pchip(xcnew1,thiscp1(Iclip1));
for n = 1:length(cs2.coefs(:,1))
fun1 = @(x) cs2.coefs(n,1)*(x-cs2.breaks(n)).^3+cs2.coefs(n,2)*(x-cs2.breaks(n)).^2+cs2.coefs(n,3)*(x-cs2.breaks(n))+cs2.coefs(n,4);
int1 = integral(fun1,cs2.breaks(n),cs2.breaks(n+1));
int3(n)=int1;
end
intall = abs(sum(int2,’all’)-sum(int3,’all’))
This is one of the several methods I’ve devised to evaluate the area between two curves drawn by each set of data points. Currently, I am experiencing some inconsistencies when my data points are greatly vertically spaced – I am wondering if there is any way to remedy this. I am also curious as to how accurate this method is, and need some more experienced minds to comment. Thanks! Honestly, I just want to know what people think of some data fitting I’ve been doing. Simply given two sets of points (xc,thiscp) and (xc1,thiscp1), I’ve managed to come up with the following piece of code:
xclip = xc(~isnan(xc));
[vals Iclip]=unique(xclip,’first’);
%
xcnew = unique(xclip);
cs = pchip(xcnew,thiscp(Iclip));
for n = 1:length(cs.coefs(:,1))
fun = @(x) cs.coefs(n,1)*(x-cs.breaks(n)).^3+cs.coefs(n,2)*(x-cs.breaks(n)).^2+cs.coefs(n,3)*(x-cs.breaks(n))+cs.coefs(n,4);
int = integral(fun,cs.breaks(n),cs.breaks(n+1));
int2(n)=int;
end
xclip1 = xc1(~isnan(xc1));
[vals Iclip1]=unique(xclip1,’first’);
xcnew1 = unique(xclip1);
cs2 = pchip(xcnew1,thiscp1(Iclip1));
for n = 1:length(cs2.coefs(:,1))
fun1 = @(x) cs2.coefs(n,1)*(x-cs2.breaks(n)).^3+cs2.coefs(n,2)*(x-cs2.breaks(n)).^2+cs2.coefs(n,3)*(x-cs2.breaks(n))+cs2.coefs(n,4);
int1 = integral(fun1,cs2.breaks(n),cs2.breaks(n+1));
int3(n)=int1;
end
intall = abs(sum(int2,’all’)-sum(int3,’all’))
This is one of the several methods I’ve devised to evaluate the area between two curves drawn by each set of data points. Currently, I am experiencing some inconsistencies when my data points are greatly vertically spaced – I am wondering if there is any way to remedy this. I am also curious as to how accurate this method is, and need some more experienced minds to comment. Thanks! spline, interpolation, raw data, aerospace MATLAB Answers — New Questions