Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: fzero  logical error
Date: Tue, 11 May 2010 21:39:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 35
Message-ID: <hscipp$bam$1@fred.mathworks.com>
References: <hschvv$lor$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1273613945 11606 172.30.248.35 (11 May 2010 21:39:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 11 May 2010 21:39:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:634798

"Vinz A" <vinzav@gmail.com> wrote in message <hschvv$lor$1@fred.mathworks.com>...
> I have problem running for the first time, the below function but when I run it again it works fine. I am unable to trace out the error. 
> 
> I am solving for 'y' and all others are defined. 
> For instance, if y is the variable, then: 
> 
> x =100; 
> Peri = 1e4; 
> rhoc = 4.5 
> ficrho = 0.9; 
> g = 9.81; 
> Fun=@(y)(x/(Peri)-(rhoc*(rhoc-ficrho)*g*(y)^3)); 
> options=['iterations','100','tolX','0.01']; 
> Fdel=fzero(Fun,1.4766*10^-5,options) 
> 
> error: 
> ??? Operands to the || and && operators must be convertible to logical scalar values. 
> 
> Error in ==> fzero at 333 
> elseif ~isfinite(fx) || ~isreal(fx) 
> 
> Error in ==>Fun=@(y)(x(4)/(Peri)-(rhoc*(rhoc-ficrho)*g*(y)^3)/; 
> 
> Can you please let me know how can I control this and tried to fix it but it doesn't work. 
> 
> Thank you for your consideration. 
> 
> Regards, 
> VJ 

  You should have y.^3 in your function so it can receive vectors as inputs for 'fzero' to work properly.

  However, I don't understand why you don't just take the appropriate cube root rather than call on 'fzero'.

Roger Stafford