vertcat error! in fsolve for 3 variables

1 view (last 30 days)
I am trying to optimse a set of 3 quadratic equations with 3 varaibles..
function Wheel_align = myfunct(C)
K1 = 5;
K2 =5;
theta1 = pi/3;
x1=0;
x2=5;
y1=0;
y2=0;
z1=0;
z2=0;
Wheel_align = [(x1 - C(1))^2 + (y1 - 4.33)^2 +(z1- C(2))^2 - (K1)^2;
(x2 - C(1))^2 + (y2 - 4.33)^2 +(z2 - C(2))^2 - (K1)^2;
(x1 - C(1))*(x2 - C(1)) + (y1 - 4.33)*(y2 - 4.33)+ (z1 - C(3))*(z2 - C(3))- abs(K1*K2)*cos(theta1);
C0 = [0;-5;0]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[C,fval] = fsolve(@myfunct,C0,options) % Call solver
ERROR is as follows:
Error using vertcat
CAT arguments dimensions are not consistent.
Error in myfunct (line 21)
Wheel_align = [(x1 - C(1))^2 + (y1 - 4.33)^2 +(z1- C(2))^2 - (K1)^2;
Error in fsolve (line 243)
fuser = feval(funfcn{3},x,varargin{:});
Error in main_wheel (line 3)
[C,fval] = fsolve(@myfunct,C0,options) % Call solver
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot
continue.

Accepted Answer

Walter Roberson
Walter Roberson on 9 Jan 2012
You should have shown us the function header for wheel_align . I will speculate that you define it as having a single parameter named C.
The length of C that is passed in is the same as the length of your starting guess, C0. Your C0 should have at least 6 elements.
  10 Comments
Walter Roberson
Walter Roberson on 9 Jan 2012
fsolve() can only find one solution, so do not worry about that aspect.
Meanwhile,
"With regard to the vertcat problem, I would have to know which line of code the problem is on. Including the entire block of code would be useful. Please edit it in to the original question, as this is a case where exact spacing can be important."
Walter Roberson
Walter Roberson on 9 Jan 2012
"And the +(z1-C(3))^2 are unary plus. "

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!