From: Frédéric Bergeron on
Hi,

I posted a message yesterday on the subject, but I didn't get any response, so I will try again to explain my problem. I'm sorry if I'm irritating anyone by posting two messages on the same problem, but since I got no answers, I think it's ok.

I'm currently programming a GUI for nivelling fields. Right now, my program draw the actual field using surf() and the best-fit plan using regress() and mesh(). The user can then draw a line on the best-fit plan to divide the field into 2 sections, so that the program calculate two best-fit planes for each of of the field section.

My problem is, when the user draw the line, the GUI traces 2 other planes instead of the initial best-fit plane, but these planes are independant at their junctions, because I use the function regress() twice with differents parts of the field. I would like to do a 2-parts regression in 3d where the 2 best-fit planes have the same intersection line. Is there a function I can use for that? I read about the Statistic Toolbox, but I didn't found a function wich does Multi-phase/segmented mutiple linear regression in 3D.

I have also tried downloading some regression programs, like the mancovan program, wich include the mStepwise.m function, but I didn't succes at making it works.

I would very apreciate if somebody responds me and give me an idea on how could I program a segmented multiple linear regression, or the name of a function you know that can handle that, or anything else. Thank you.

Best regards,

P.S.: I'm sorry if I made some English mistakes writing this message. English is my second language.
From: Bruno Luong on
"Frédéric Bergeron" <frederic.bergeron(a)logiag.com> wrote in message <hur1uk$qto$1(a)fred.mathworks.com>...
> Hi,
>
> I posted a message yesterday on the subject, but I didn't get any response, so I will try again to explain my problem. I'm sorry if I'm irritating anyone by posting two messages on the same problem, but since I got no answers, I think it's ok.
>
> I'm currently programming a GUI for nivelling fields. Right now, my program draw the actual field using surf() and the best-fit plan using regress() and mesh(). The user can then draw a line on the best-fit plan to divide the field into 2 sections, so that the program calculate two best-fit planes for each of of the field section.
>
> My problem is, when the user draw the line, the GUI traces 2 other planes instead of the initial best-fit plane, but these planes are independant at their junctions, because I use the function regress() twice with differents parts of the field. I would like to do a 2-parts regression in 3d where the 2 best-fit planes have the same intersection line. Is there a function I can use for that? I read about the Statistic Toolbox, but I didn't found a function wich does Multi-phase/segmented mutiple linear regression in 3D.
>
> I have also tried downloading some regression programs, like the mancovan program, wich include the mStepwise.m function, but I didn't succes at making it works.
>
> I would very apreciate if somebody responds me and give me an idea on how could I program a segmented multiple linear regression, or the name of a function you know that can handle that, or anything else. Thank you.
>
> Best regards,
>
> P.S.: I'm sorry if I made some English mistakes writing this message. English is my second language.

You can do the regression:

z ~ a1*x + b1*y + c1 for { (x,y,z) data on set # 1, e.g., left side of the line }
z ~ a2*x + b2*y + c2 for { (x,y,z) data on set # 2, e.g., right side of the line }

Under the constraints

a1*x + b1*y + c1 = a2*x + b2*y + c2 for { (x,y) two (arbitrary) points on the line }.

Bruno
From: Frédéric Bergeron on
>
> You can do the regression:
>
> z ~ a1*x + b1*y + c1 for { (x,y,z) data on set # 1, e.g., left side of the line }
> z ~ a2*x + b2*y + c2 for { (x,y,z) data on set # 2, e.g., right side of the line }
>
> Under the constraints
>
> a1*x + b1*y + c1 = a2*x + b2*y + c2 for { (x,y) two (arbitrary) points on the line }.
>
> Bruno

Thank you.
I understand what you say, because defining the constraint will force the coefficients to be dependent, so the regression planes will pass through the same line...

But how do I set this constraint?

According to my Matlab experience, I think I would do a FOR or WHILE loop to calculate the a1,b1,c1 and a2,b2,c2 coefficients a lots of time, each time evaluating the 'constraint' and see if it is respected, then finish the loop.

Is there another way to set this constraint?

Thank you for your help!
From: Bruno Luong on
"Frédéric Bergeron" <frederic.bergeron(a)logiag.com> wrote in message <hur3j4$gno$1(a)fred.mathworks.com>...
> >
> > You can do the regression:
> >
> > z ~ a1*x + b1*y + c1 for { (x,y,z) data on set # 1, e.g., left side of the line }
> > z ~ a2*x + b2*y + c2 for { (x,y,z) data on set # 2, e.g., right side of the line }
> >
> > Under the constraints
> >
> > a1*x + b1*y + c1 = a2*x + b2*y + c2 for { (x,y) two (arbitrary) points on the line }.
> >
> > Bruno
>
> Thank you.
> I understand what you say, because defining the constraint will force the coefficients to be dependent, so the regression planes will pass through the same line...
>
> But how do I set this constraint?
>
> According to my Matlab experience, I think I would do a FOR or WHILE loop to calculate the a1,b1,c1 and a2,b2,c2 coefficients a lots of time, each time evaluating the 'constraint' and see if it is respected, then finish the loop.
>
> Is there another way to set this constraint?

Yes, just write down the linear system with constraints. The code should goes like this (I have not checked it)

% (x,y,x) are three input vectors of data
% Assuming the line is x=y
set1 = x <= y; % upper
set2 = ~set1; % lower

x = x(:);
y = y(:);
z = z(:);

M1 = [x(set1) y(set1) ones(sum(set1),1)];
M2 = [x(set2) y(set2) ones(sum(set2),1)];
M = blkdiag(M1,M2);
Aeq = [0 0 1 0 0 -1; % match z at (x,y)=(0,0)
1 1 1 -1 -1 -1]; % match z at (x,y)=(1,1)
B = null(Aeq);
rhs = [z(set1); z(set2)];
sol = B*((M*B)\z);
a1 = sol(1)
b1 = sol(2)
c1 = sol(3)
a2 = sol(4)
b2 = sol(5)
c2 = sol(6)

% Bruno
From: Frédéric Bergeron on
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hur5l9$4g9$1(a)fred.mathworks.com>...

>
> Yes, just write down the linear system with constraints. The code should goes like this (I have not checked it)
>
> % (x,y,x) are three input vectors of data
> % Assuming the line is x=y
> set1 = x <= y; % upper
> set2 = ~set1; % lower
>
> x = x(:);
> y = y(:);
> z = z(:);
>
> M1 = [x(set1) y(set1) ones(sum(set1),1)];
> M2 = [x(set2) y(set2) ones(sum(set2),1)];
> M = blkdiag(M1,M2);
> Aeq = [0 0 1 0 0 -1; % match z at (x,y)=(0,0)
> 1 1 1 -1 -1 -1]; % match z at (x,y)=(1,1)
> B = null(Aeq);
> rhs = [z(set1); z(set2)];
> sol = B*((M*B)\z);
> a1 = sol(1)
> b1 = sol(2)
> c1 = sol(3)
> a2 = sol(4)
> b2 = sol(5)
> c2 = sol(6)
>
> % Bruno

Thanks

I understand what you're doing, but in the division line where you solves the problem, shouldn't the last term be rhs instead of z?
i.e. sol = B*((M*B)\rhs); instead of sol = B*((M*B)\z); ?

Also, I've never utilised the function null. Wouldn't the code work without this function?
i.e. simply write sol = M\rhs; ?
 |  Next  |  Last
Pages: 1 2
Prev: Java problem
Next: install Matlab R2010b on Mac?