From: Matt J on 24 Mar 2010 14:28 "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hodkv0$5vm$1(a)fred.mathworks.com>... > Namely, we pose the problem as follows > > min. > > (y1 - (ax^2 + bx + c))^2 + (y2 - (dx^2 + ex + f))^2 > > subject to > > Discriminant=(b-e)^2-4*(a-d)*(c-f)>=a^2*MinDist^2 > > where MinDist>0 would be the a priori lower bound on the separation distance between the intersection points. =============== Make that (b-e)^2-4*(a-d)*(c-f) >= (a-d)^2*MinDist^2 Also, you would need an additional constraint on curvature differences (a-d)^2>=tol>0 Still doesn't seem too bad, though.
From: Alexandra on 25 Mar 2010 13:23 "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hodfvm$be4$1(a)fred.mathworks.com>... > "Alexandra " <klanga_uk(a)yahoo.co.uk> wrote in message <hodaql$c8a$1(a)fred.mathworks.com>... > > I want to fit two functions to two data sets > > y1 = ax^2 + bx + c = fit for data set 1 > > y2 = dx^2 + ex + f = fit for data set 2 > > I know that the curves must intersect at two points given by > > y1=y2 at [x=A,y1] > > y1=y2 at [x=B,y2] > > I would like to calculate the intersection points from the data also but if this is not possible I can estimate them. > > Using this information, how do I find the values for a,b,c,d,e,f? > > You have two quadratic polynomials, with unknown > coefficients. You do have data points that can be > used to fit the curves, but an additional piece of > information is that the curves MUST cross at two > specific locations in x. > > If you do not know the locations of the intersection > points, then you might choose to use polyfit on each > curve independently, then compute the intersections. > You would do that by applying roots to the difference > of the two functions. Thus > > roots(y1 - y2) > > will yield two locations. They are the locations in x > where the curves cross. > > If you decide that these locations are in fact already > known, then the estimation process is different. > > Thus, at x = A, y1(A) = y2(A), and at x = B, we > have y1(B) = y2(B). The function values at those > points are not known here, only that the curves must > cross at those points. This problem is solved using > a linear least squares with equality constraints. lsqlin > from the optimization toolbox will do it, or if you do > not have that TB, then download lse from the FEX. > > http://www.mathworks.com/matlabcentral/fileexchange/13835 > > Assume that we have curve 1 defined at a set of points > with (x1,y1), where x1 and y1 are vectors. We also > have (x2,y1), vectors that contain data for the second > curve. Then estimate the coefficients as: > > x1 = x1(:); > x2 = x2(:); > n1 = numel(x1); > n2 = numel(x2); > M = [[x1.^2, x2, ones(n1,1),zeros(n1,3)]; ... > [zeros(n2,3),x2.^2, x2, ones(n2,1)]]; > > Aeq= [A.^2,A,1,-A.^2,-A,-1;B.^2,B,1,-B.^2,-B,-1]; > coef = lsqlin(M,[y1(:);y2(:)],[],[],Aeq,[0;0]); > p1 = coef(1:3); > p2 = coef(4:6); > > HTH, > John Thanks John! I'll try your solution and let you know how I get on. Alex
First
|
Prev
|
Pages: 1 2 Prev: DC-blocking filter using MATLAB filter function Next: Large Matrix - Replacing NaN with zeros |