MATLAB: How to solve a constrained linear least squares problem where the constraint depends on elements in the solution

constraintlinear optimization

I have simplified the problem for ease of exposition.
I am solving for x in A*x = b. If x = [x1,x2,x3,x4], I require that x3 = (x4 – x2)./2;
My starting point was the lsqlin function, but I am unsure about how to implement the constraint.
A = [ (1+.0129*.5) 0 0 0; 0 (1+.0164) 0 0; (.0132*.5) (.0132*.5) (.0132*.5) (1+.0132*.5) ];
b = [1;1;1];
Thanks

Best Answer

A=[ (1+.0129*.5) 0 0 0; 0 (1+.0164) 0 0; (.0132*.5) (.0132*.5) (.0132*.5) (1+.0132*.5);0 1 2 -1 ];
b=[1;1;1;0];
sol=A\b
Best wishes
Torsten.