thank you for your quick reply. It took me some time and help from people at my university (TU Delft), but I got it right now. I developed a script to do what I asked you for. It solves the polynomial in a different way, by using mldivide. It uses the fact that overdetermined matrices are solved by a least squares fit.
If you are interested, I could mail my script to you.
I am currently searching to minimize influence of different pieces (between the breaks) on one another. I want to have a high degree polynomial (10 and up) but only have the total piecewise polynomial differentiable up to 3rd or 4th order.
I think I only need to change a line or two in the splinebase function, but I wouldn't know which, since I do not understand the fine details of it, in spite the very crisp and clear code you wrote.
I'd really appreciate your help, thank you in advance.
Thanks for this functions. It was very helpfull.
I would just remocomend the use of bsxfun instead of repmat, simpy because it's faster. The equivalent would be I believe:
[i, j] = find(bsxfun(@le, min(x1(1:end-1),x1(2:end)), max(x2(1:end-1),x2(2:end)).') & ...
bsxfun(@ge, max(x1(1:end-1),x1(2:end)), min(x2(1:end-1),x2(2:end)).') & ...
bsxfun(@le, min(y1(1:end-1),y1(2:end)), max(y2(1:end-1),y2(2:end)).') & ...
bsxfun(@ge, max(y1(1:end-1),y1(2:end)), min(y2(1:end-1),y2(2:end)).'));
Thanks again, Pedro
Ilya and Jan, because of floating point arithmetic, it's impossible to find intersections perfectly in all cases. Jan, your example has two curves that touch at a single point; some people might define this as an intersection. Your assertion that (0,0) isn't an intersection is debatable.
It also erroneously finds contact points (no real intersections).
Example: [x0, y0] = intersections([-1,0,-1], [-1,0,1], [1, 0, 1], [-1,0,1], 1);
returns point (0, 0) as intersection point although it isn't.