From: Els on 28 May 2010 09:33 I try to solve a couple of nonlinear equations with the following function -------------------- function F = SolveNG(x,cx,cy,cz,ax,ay,az,P4,P5,CP) n = cross(P4-CP',P4-P5); n = n(:).'/norm(n) D1 = -n(1,1)*P4(1,1) - n(1,2)*P4(1,2) - n(1,3)*P4(1,3) P1=P4(1,1); P2=P4(1,2); P3=P4(1,3); N1=n(1,1) N2=n(1,2) N3=n(1,3) F = [N1*x(1) + N2*x(2) + N3*x(3) + D1; ((x(1)-cx)/ax)^2 + ((x(2)-cy)/ay)^2 + ((x(3)-cz)/az)^2 -1; ((2*(x(1)-cx))/(ax^2))- x(4); ((2*(x(2)-cy))/(ay^2))- x(5); ((2*(x(3)-cz))/(az^2))- x(6); x(4)*x(1) + x(5)*x(2) + x(6)*x(3)+ x(7); x(4)*P1 + x(5)*P2 + x(6)*P3+ x(7)]; end ------------------- In the main function I use this code to call my function ------------------- x0 = [-80; -40; -40;-30;-30;-30;-30]; % Make a starting guess at the solution options=optimset('Display','iter'); % Option to display output fsolve(@SolveNG, x0, options, cx,cy,cz,ax,ay,az,P4,P5,CP) ------------------ But I get an error which I do not understand: ??? Error using ==> vertcat CAT arguments dimensions are not consistent. Error in ==> SolveNG at 12 F = [N1*x(1) + N2*x(2) + N3*x(3) + D1; Error in ==> fsolve at 253 fuser = feval(funfcn{3},x,varargin{:}); Error in ==> TestSimpeSphere at 726 fsolve(@SolveNG, x0, options, cx,cy,cz,ax,ay,az,P4,P5,CP) Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue. How can I solve this??
|
Pages: 1 Prev: Function callback when variable deleted Next: comsol to matlab |