vertcat error! in fsolve for 3 variables

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.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Jan. 2012

0 Stimmen

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 Kommentare

Shobhit@
Shobhit@ am 9 Jan. 2012
Hi here is the function header.
function Wheel_align = myfun(C)
i still can't understand where i am making the mistake
Shobhit@
Shobhit@ am 9 Jan. 2012
How do i change the length of C and how do i specify the 6 starting guess for the solution for all 6 varaibles
Shobhit@
Shobhit@ am 9 Jan. 2012
I changed C0 = [ -5;-5;-5;-5;-5;-5]
so that length becomes 6 but i am getting the following error now
"Error using vertcat
CAT arguments dimensions are not consistent."
Walter Roberson
Walter Roberson am 9 Jan. 2012
By the way, Maple says that there is no solution.
The set can be broken up into two non-intersecting subsets, three equations in C1, C2, C3, and three equations in C4, C5, C6.
Maple thinks the equations in C1, C2, C3 are not consistent.
Unfortunately when I step through it solving the triple manually, I am getting stuck in the back substitutions after solving for the second variable.
Walter Roberson
Walter Roberson am 9 Jan. 2012
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 am 9 Jan. 2012
Your -(K1)^2 terms are going to be treated as separate elements in the list, because - immediately followed (no space) by an expression is unary minus rather than subtraction. And the +(z1-C(3))^2 are unary plus. Spacing is important! Use a space before and a space after those operators.
Shobhit@
Shobhit@ am 9 Jan. 2012
same problem persists....... maybe my sample values are wrong let me try with the correct one .....
but what is this vertcat error??
Shobhit@
Shobhit@ am 9 Jan. 2012
Is the error because two separate values can satisfy my equations .. since they are quadratic??
Walter Roberson
Walter Roberson am 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 am 9 Jan. 2012
"And the +(z1-C(3))^2 are unary plus. "

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by