Prev: Axes object, zoom problem
Next: beginner question
From: Yu Li on 21 Jun 2010 12:53 I am trying to solve a function as below: function F = B1B2(M,x,k11,L20,k21,k22,J20,H21,MT,NT) global k11 L20 k21 k22 MT NT J20 H21; F = 2*L20.*M.^2.*(1+k21.*x+k22.*k21.*x.^2) + M.*(1+k11.*x+... J20.*NT./(1 + J20.*M + H21.*x.*J20.*M)+... H21.*J20.*(NT./(1 + J20.*M + H21.*x.*J20.*M)).*x)-MT; Then I call it from main function: [M,fval,exitflag,output] = fzero(@(M) B1B2(M,x), MT) I checked older posts and make all my *, ^ and / scalar. But I still got the error message Operands to the || and && operators must be convertible to logical scalar values. Error in ==> fzero at 333 elseif ~isfinite(fx) || ~isreal(fx) Anyone has any clue what is going on?
From: Torsten Hennig on 21 Jun 2010 22:46 > I am trying to solve a function as below: > function F = B1B2(M,x,k11,L20,k21,k22,J20,H21,MT,NT) > > global k11 L20 k21 k22 MT NT J20 H21; > > F = 2*L20.*M.^2.*(1+k21.*x+k22.*k21.*x.^2) + > M.*(1+k11.*x+... > J20.*NT./(1 + J20.*M + H21.*x.*J20.*M)+... > H21.*J20.*(NT./(1 + J20.*M + > *M + H21.*x.*J20.*M)).*x)-MT; > > Then I call it from main function: > > [M,fval,exitflag,output] = fzero(@(M) B1B2(M,x), MT) > > I checked older posts and make all my *, ^ and / > scalar. But I still got the error message Operands to > the || and && operators must be convertible to > logical scalar values. > > Error in ==> fzero at 333 > elseif ~isfinite(fx) || ~isreal(fx) > > Anyone has any clue what is going on? 1. k11,L20,k21,k22,J20,H21,MT,NT are global variables ; they need not appear in the list of parameters for B1B2. 2. The parameter lists for B1B2 in function F = B1B2(M,x,k11,L20,k21,k22,J20,H21,MT,NT) and in the call to fzero fzero(@(M) B1B2(M,x), MT) do not fit. 3. Did you assign a value to the variables you use, especially MT ? Best wishes Torsten.
From: Steven Lord on 22 Jun 2010 13:50 "Yu Li" <yuliyy(a)gmail.com> wrote in message news:hvo5e3$rf4$1(a)fred.mathworks.com... >I am trying to solve a function as below: function F = >B1B2(M,x,k11,L20,k21,k22,J20,H21,MT,NT) > > global k11 L20 k21 k22 MT NT J20 H21; > > F = 2*L20.*M.^2.*(1+k21.*x+k22.*k21.*x.^2) + M.*(1+k11.*x+... > J20.*NT./(1 + J20.*M + H21.*x.*J20.*M)+... > H21.*J20.*(NT./(1 + J20.*M + H21.*x.*J20.*M)).*x)-MT; > > Then I call it from main function: > [M,fval,exitflag,output] = fzero(@(M) B1B2(M,x), MT) > > I checked older posts and make all my *, ^ and / scalar. But I still got > the error message Operands to the || and && operators must be convertible > to logical scalar values. > > Error in ==> fzero at 333 > elseif ~isfinite(fx) || ~isreal(fx) > > Anyone has any clue what is going on? FZERO requires the function that you pass in as its first input to return a SCALAR value -- you would receive this error if that function returned a NONscalar value. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
|
Pages: 1 Prev: Axes object, zoom problem Next: beginner question |