From: Vinz A on
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
From: Steven Lord on

"Vinz A" <vinzav(a)gmail.com> wrote in message
news:hschvv$lqd$1(a)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'];

This is incorrect. FZERO expects an options _structure_; that code simply
creates the string 'iterations100tolX0.01'. Use OPTIMSET instead to create
an actual options structure and pass it into FZERO.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Roger Stafford on
"Vinz A" <vinzav(a)gmail.com> wrote in message <hschvv$lor$1(a)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
From: Walter Roberson on
Vinz A wrote:
> 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));

There is a difference between the Fun you define here, and

> 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)/;

the Fun that is printed out in the error message.

The one in the error message references x(4) where the other references just
x, and the one in the error message ends with a / (which is not valid syntax.)

> Can you please let me know how can I control this and tried to fix it
> but it doesn't work.

If you have not misquoted anything, then you have somehow managed to wind up
with different Fun at run time; if so, then exiting Matlab and re-entering
should probably fix the problem. If you have managed to misquote something,
then we need to see actual information and error message.