Jordan O'Neill
Jordan O'Neill

Reputation: 1

matrix in function, fzero not working

There are a lot of variables here so bear with me. After debugging etc. all of the variables are working fine except for Tinf so assume that all other variables are constant. Tinf is defined as

Tinf=34.5*cos((2*pi).*(t-5))+275.5

which is a function of t where t is

t=linspace(0,50,600)

I am trying to calculate

T(1)=fzero(fun_Partridge,0)

where

fun_Partridge=@(x) ((I(1).^2).*Rprime(1))+(Alpha.*D(1).*Gs)-(o*E*pi.*D(1).*(x.^4-Tinf.^4))-(h*pi.*D(1).*(x-Tinf))

(remember that all other variables are working and therefore essentially constants, also the variables that are matrices are only two columns of one value each)

Everything runs fine until

T(1)=fzero(fun_Partridge,0)

and I get the error message:

" Operands to the || and && operators must be convertible to logical scalar values.

Error in fzero (line 308) elseif ~isfinite(fx) || ~isreal(fx)

Error in MaxSag_Take_2 (line 102) T(1)=fzero(fun_Partridge,0); "

I am very much a beginner when it comes to MatLab so please don't hesitate to dumb things down a bit. Thanks in advance!

Upvotes: 0

Views: 786

Answers (1)

craigim
craigim

Reputation: 3914

Without knowing the size, shape, and type that your other variables are, it's difficult to say, but based on that error message, fx should be a scalar and it's coming out as a vector, which means you're passing something to fzero that it doesn't like.

I do not have MATLAB in front of me right now, but looking at your fun_Partridge function, you are doing matrix multiplication of some variables, and element-wise multiplication of others. If o and/or E are vectors, you may be ending up with a matrix instead of a vector function, which, if fzero is constructing fx using a function like sum, would yield a vector instead of a scalar, causing the short-circuit behavior of the && and || to choke.

In addition to @NKN's comment above, try executing size(fun_Partridge(1)) and see if you get out a vector or a matrix.

Upvotes: 0

Related Questions