I need to add piecewise polynomials derived from multiple datasets. Is there an easy way to add piecewise polynomials together without interpolating? In other words, given PP1 and PP2, is there a way to generate PP3 (where PP3 remains in a piecewise polynomial form)? e.g...
t1 = linspace(0,1,5);
t2 = linspace(0,1,7);
pp1 = spline(t1,sin(pi*t1));
pp2 = spline(t2,t2.^2);
close all
hold on
tnew = linspace(0,1,50);
h(:,1) = plot(tnew,ppval(pp1,tnew));
plot(t1,ppval(pp1,t1),'bs')
h(:,2) = plot(tnew,ppval(pp2,tnew));
plot(t2,ppval(pp2,t2),'rs')
h(:,3) = plot(tnew,ppval(pp1,tnew)+ppval(pp2,tnew));
legend(h,{'spline of sin(\pi t)','spline of t^2','sin(\pi t)+t^2'},...
'location','northwest')
xlabel('t')
But instead of specifying tnew
explicitly, I would like a new piecewise polynomial pp3
that is effectively pp1
+pp2
.