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:
calculation of zeros of a function

Subject: calculation of zeros of a function

From: pietro

Date: 20 Jan, 2011 17:07:05

Message: 1 of 9

Hi guys,

I'm trying to learn fzero function, however I don't understand how I don't get any results in my case. In the beginning I have tried with a symbolic calculation and later I have applied with a numerical one.

 fzero(@(mu1)0.018-0.25*sqrt((mu1+mu1^2)/(1+3/4*mu1)),0)
Exiting fzero: aborting search for an interval containing a sign change
    because complex function value encountered during search.
(Function value at -0.0282843 is 0.018-0.041893i.)
Check function or try again with a different starting value.

ans =

   NaN

>> mu=double(solve('0.018-0.25*sqrt((mu_s+mu_s^2)/(1+3/4*mu_s))',mu_s))

mu =

    0.0052
   -1.0013

As you can see I get no results with fzero. What is wrong in my code?
Thanks

Pietro

Subject: calculation of zeros of a function

From: Steven_Lord

Date: 20 Jan, 2011 17:50:21

Message: 2 of 9



"pietro " <bracardi82@email.it> wrote in message
news:ih9q3p$ivo$1@fred.mathworks.com...
> Hi guys,
> I'm trying to learn fzero function, however I don't understand how I don't
> get any results in my case. In the beginning I have tried with a symbolic
> calculation and later I have applied with a numerical one.
>
> fzero(@(mu1)0.018-0.25*sqrt((mu1+mu1^2)/(1+3/4*mu1)),0)
> Exiting fzero: aborting search for an interval containing a sign change
> because complex function value encountered during search.
> (Function value at -0.0282843 is 0.018-0.041893i.)
> Check function or try again with a different starting value.

Because you specified a scalar as the guess, FZERO had to try to locate an
interval over which your objective function changed sign. In doing so, it
chose to evaluate your objective function at a value of mu1 for which the
expression ((mu1+mu1^2)/(1+3/4*mu1)) becomes negative. Since the square
root of a negative number is complex, and FZERO cannot work with objective
functions that return complex values, FZERO told you that it had to exit.

You should specify an interval over which the objective function always
returns a real value and for which the values of the objective function
evaluated at the endpoints have different signs.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: calculation of zeros of a function

From: pietro

Date: 21 Jan, 2011 08:38:04

Message: 3 of 9

"Steven_Lord" <slord@mathworks.com> wrote in message <ih9skt$6nq$1@fred.mathworks.com>...
>
>
> "pietro " <bracardi82@email.it> wrote in message
> news:ih9q3p$ivo$1@fred.mathworks.com...
> > Hi guys,
> > I'm trying to learn fzero function, however I don't understand how I don't
> > get any results in my case. In the beginning I have tried with a symbolic
> > calculation and later I have applied with a numerical one.
> >
> > fzero(@(mu1)0.018-0.25*sqrt((mu1+mu1^2)/(1+3/4*mu1)),0)
> > Exiting fzero: aborting search for an interval containing a sign change
> > because complex function value encountered during search.
> > (Function value at -0.0282843 is 0.018-0.041893i.)
> > Check function or try again with a different starting value.
>
> Because you specified a scalar as the guess, FZERO had to try to locate an
> interval over which your objective function changed sign. In doing so, it
> chose to evaluate your objective function at a value of mu1 for which the
> expression ((mu1+mu1^2)/(1+3/4*mu1)) becomes negative. Since the square
> root of a negative number is complex, and FZERO cannot work with objective
> functions that return complex values, FZERO told you that it had to exit.
>
> You should specify an interval over which the objective function always
> returns a real value and for which the values of the objective function
> evaluated at the endpoints have different signs.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Hi Steve,

Thanks Steve, with your suggestion I have got the solution. However I would like know, how to decide the interval if I don't have any idea about the solution. Do you have any suggestion?

Thanks again

Best regards

Michele

Subject: calculation of zeros of a function

From: Torsten Hennig

Date: 21 Jan, 2011 08:56:24

Message: 4 of 9

> "Steven_Lord" <slord@mathworks.com> wrote in message
> <ih9skt$6nq$1@fred.mathworks.com>...
> >
> >
> > "pietro " <bracardi82@email.it> wrote in message
> > news:ih9q3p$ivo$1@fred.mathworks.com...
> > > Hi guys,
> > > I'm trying to learn fzero function, however I
> don't understand how I don't
> > > get any results in my case. In the beginning I
> have tried with a symbolic
> > > calculation and later I have applied with a
> numerical one.
> > >
> > >
> fzero(@(mu1)0.018-0.25*sqrt((mu1+mu1^2)/(1+3/4*mu1)),0
> )
> > > Exiting fzero: aborting search for an interval
> containing a sign change
> > > because complex function value encountered
> during search.
> > > (Function value at -0.0282843 is
> 0.018-0.041893i.)
> > > Check function or try again with a different
> starting value.
> >
> > Because you specified a scalar as the guess, FZERO
> had to try to locate an
> > interval over which your objective function changed
> sign. In doing so, it
> > chose to evaluate your objective function at a
> value of mu1 for which the
> > expression ((mu1+mu1^2)/(1+3/4*mu1)) becomes
> negative. Since the square
> > root of a negative number is complex, and FZERO
> cannot work with objective
> > functions that return complex values, FZERO told
> you that it had to exit.
> >
> > You should specify an interval over which the
> objective function always
> > returns a real value and for which the values of
> the objective function
> > evaluated at the endpoints have different signs.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > To contact Technical Support use the Contact Us
> link on
> > http://www.mathworks.com
>
> Hi Steve,
>
> Thanks Steve, with your suggestion I have got the
> solution. However I would like know, how to decide
> the interval if I don't have any idea about the
> solution. Do you have any suggestion?
>
> Thanks again
>
> Best regards
>
> Michele

Instead of solving 0.018-0.25*sqrt((x+x^2)/(1+0.75*x))=0,
you could also solve 0.018^2-0.25^2*(x+x^2)/(1+0.75*x)=0
for x.
In this case, the difficulties should not arise.

But check whether the x obtained also satisfies
your original equation.

Best wishes
Torsten.

Subject: calculation of zeros of a function

From: pietro

Date: 21 Jan, 2011 21:56:08

Message: 5 of 9

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <463040793.3204.1295600214370.JavaMail.root@gallium.mathforum.org>...
> > "Steven_Lord" <slord@mathworks.com> wrote in message
> > <ih9skt$6nq$1@fred.mathworks.com>...
> > >
> > >
> > > "pietro " <bracardi82@email.it> wrote in message
> > > news:ih9q3p$ivo$1@fred.mathworks.com...
> > > > Hi guys,
> > > > I'm trying to learn fzero function, however I
> > don't understand how I don't
> > > > get any results in my case. In the beginning I
> > have tried with a symbolic
> > > > calculation and later I have applied with a
> > numerical one.
> > > >
> > > >
> > fzero(@(mu1)0.018-0.25*sqrt((mu1+mu1^2)/(1+3/4*mu1)),0
> > )
> > > > Exiting fzero: aborting search for an interval
> > containing a sign change
> > > > because complex function value encountered
> > during search.
> > > > (Function value at -0.0282843 is
> > 0.018-0.041893i.)
> > > > Check function or try again with a different
> > starting value.
> > >
> > > Because you specified a scalar as the guess, FZERO
> > had to try to locate an
> > > interval over which your objective function changed
> > sign. In doing so, it
> > > chose to evaluate your objective function at a
> > value of mu1 for which the
> > > expression ((mu1+mu1^2)/(1+3/4*mu1)) becomes
> > negative. Since the square
> > > root of a negative number is complex, and FZERO
> > cannot work with objective
> > > functions that return complex values, FZERO told
> > you that it had to exit.
> > >
> > > You should specify an interval over which the
> > objective function always
> > > returns a real value and for which the values of
> > the objective function
> > > evaluated at the endpoints have different signs.
> > >
> > > --
> > > Steve Lord
> > > slord@mathworks.com
> > > To contact Technical Support use the Contact Us
> > link on
> > > http://www.mathworks.com
> >
> > Hi Steve,
> >
> > Thanks Steve, with your suggestion I have got the
> > solution. However I would like know, how to decide
> > the interval if I don't have any idea about the
> > solution. Do you have any suggestion?
> >
> > Thanks again
> >
> > Best regards
> >
> > Michele
>
> Instead of solving 0.018-0.25*sqrt((x+x^2)/(1+0.75*x))=0,
> you could also solve 0.018^2-0.25^2*(x+x^2)/(1+0.75*x)=0
> for x.
> In this case, the difficulties should not arise.
>
> But check whether the x obtained also satisfies
> your original equation.
>
> Best wishes
> Torsten.

Thanks Torsten, I will try

Regards

Michele

Subject: calculation of zeros of a function

From: Think two, count blue.

Date: 21 Jan, 2011 22:59:13

Message: 6 of 9

On 11-01-21 02:56 AM, Torsten Hennig wrote:

> Instead of solving 0.018-0.25*sqrt((x+x^2)/(1+0.75*x))=0,
> you could also solve 0.018^2-0.25^2*(x+x^2)/(1+0.75*x)=0
> for x.
> In this case, the difficulties should not arise.

That would appear to neglect the cross-product of the squaring process

(a+b)^2 = a^2 + b^2 + 2*a*b

and the b would continue to be the sqrt() expression. We know that a is
non-zero so in order for a^2 + b^2 to be the same as a^2 + b^2 + 2*a*b then b
would have to be 0, but when that was carried over to a^2 + b^2 then we would
simplify to a^2 = 0 which is not the case. Thus by way of contradiction, the
2*a*b term will make a difference to the solution and solving a^2 + b^2 will
not give you a solution for a + b

Subject: calculation of zeros of a function

From: Miroslav Balda

Date: 21 Jan, 2011 23:30:23

Message: 7 of 9

Hi Michele,
If you try
     format long
     fun = @(mu1) (0.018/0.25)^2 - (mu1+mu1^2)/(1+3/4*mu1);
     [x,ssq,cnt] = LMFnlsq(fun,1,'Display',-1) % FEX Id: 17534
you will get almost perfect zero in 4 iterations:
******************************************************************* itr nfJ SUM(r^2) x dx
******************************************************************* 0 1 1.2943e+000 1.0000e+000 0.0000e+000
   1 2 4.4769e-003 7.0900e-002 9.2910e-001
   2 3 8.8669e-007 6.1163e-003 6.4784e-002
   3 4 4.7300e-014 5.1775e-003 9.3879e-004
 
   4 5 1.6814e-028 5.1773e-003 2.1693e-007
x =
   0.005177324747093
ssq =
    1.681445927325813e-028
cnt =
     4

The function LMFnlsq you will find at
       www.mathworks.com/matlabcentral/fileexchange/17534
Mira

Subject: calculation of zeros of a function

From: Torsten Hennig

Date: 25 Jan, 2011 09:00:32

Message: 8 of 9

> On 11-01-21 02:56 AM, Torsten Hennig wrote:
>
> > Instead of solving
> 0.018-0.25*sqrt((x+x^2)/(1+0.75*x))=0,
> > you could also solve
> 0.018^2-0.25^2*(x+x^2)/(1+0.75*x)=0
> > for x.
> > In this case, the difficulties should not arise.
>
> That would appear to neglect the cross-product of the
> squaring process
>
> (a+b)^2 = a^2 + b^2 + 2*a*b
>
> and the b would continue to be the sqrt() expression.
> We know that a is
> non-zero so in order for a^2 + b^2 to be the same as
> a^2 + b^2 + 2*a*b then b
> would have to be 0, but when that was carried over to
> a^2 + b^2 then we would
> simplify to a^2 = 0 which is not the case. Thus by
> way of contradiction, the
> 2*a*b term will make a difference to the solution and
> solving a^2 + b^2 will
> not give you a solution for a + b

0.018-0.25*sqrt((x+x^2)/(1+0.75*x)) = 0
->
0.018=0.25*sqrt((x+x^2)/(1+0.75*x))
->
0.018^2=0.25^2*(x+x^2)/(1+0.75*x)
->
0.018^2-0.25^2*(x+x^2)/(1+0.75*x) = 0

Best wishes
Torsten.

Subject: calculation of zeros of a function

From: pietro

Date: 27 Jan, 2011 08:01:05

Message: 9 of 9

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <ihd4uf$bgc$1@fred.mathworks.com>...
> Hi Michele,
> If you try
> format long
> fun = @(mu1) (0.018/0.25)^2 - (mu1+mu1^2)/(1+3/4*mu1);
> [x,ssq,cnt] = LMFnlsq(fun,1,'Display',-1) % FEX Id: 17534
> you will get almost perfect zero in 4 iterations:
> ******************************************************************* itr nfJ SUM(r^2) x dx
> ******************************************************************* 0 1 1.2943e+000 1.0000e+000 0.0000e+000
> 1 2 4.4769e-003 7.0900e-002 9.2910e-001
> 2 3 8.8669e-007 6.1163e-003 6.4784e-002
> 3 4 4.7300e-014 5.1775e-003 9.3879e-004
>
> 4 5 1.6814e-028 5.1773e-003 2.1693e-007
> x =
> 0.005177324747093
> ssq =
> 1.681445927325813e-028
> cnt =
> 4
>
> The function LMFnlsq you will find at
> www.mathworks.com/matlabcentral/fileexchange/17534
> Mira

Hi Mira,

Interesting, I will try to use it too...

Thanks for the suggestion

Pietro

Tags for this Thread

No tags are associated with 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