I have two pairs of curves and every pair has an intersection point at a different time value (x-value). Now I need to move one curve of each pair e
There is no need for fmincon
- the error finally was a quite simple one.
In this line: t2 = t2 - d
I assummed t2
would be the original one from the initial function call, but thats not right. It is overwritten with every iteration and therefore increasing gradually.
A temporary variable tt
solved the problem.
Final result:
function [ t1,x1,y1,t2,x2,y2 ] = findIntersectPair(t1,x1,y1,t2,x2,y2)
[d,dxy] = fminsearch(@findDelay,0);
function dxy = findDelay( d )
tt = t2 - d;
ipx = InterX([t1;x1],[tt;x2]);
ipy = InterX([t1;y1],[tt;y2]);
dxy = abs(ipx(1)-ipy(1));
end
[t1,x1,y1,x2,y2] = deal(t1,x1,y1,x2,y2);
t2 = t2 - d;
end
gives the desired plot: