Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fzero logical error

Subject: fzero logical error

From: Vinz A

Date: 11 May, 2010 21:25:19

Message: 1 of 2

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

Subject: fzero logical error

From: Roger Stafford

Date: 11 May, 2010 21:39:05

Message: 2 of 2

"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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us