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:
How to find roots using similar command like "fzero"?

Subject: How to find roots using similar command like "fzero"?

From: Nirmal

Date: 7 Sep, 2010 18:37:04

Message: 1 of 4

Hello Everyone,

I am trying to find the roots of the following two expressions.
a. tan(x)+k*x=0;
b. cot(x)-k*x=0;
where k is an array, k=200/n; and n=1:1:250.
I tried to find the these roots using the function "fzero" but the roots of tan(), cot() involving terms is the limitation of this function. Can anyone help me to find the roots by any other available functions in MATLAB?

Thank you in advance.
~Neil.

Subject: How to find roots using similar command like "fzero"?

From: Sean

Date: 7 Sep, 2010 19:47:06

Message: 2 of 4

"Nirmal " <nirmal323@yahoo.com> wrote in message <i660og$rne$1@fred.mathworks.com>...
> Hello Everyone,
>
> I am trying to find the roots of the following two expressions.
> a. tan(x)+k*x=0;
> b. cot(x)-k*x=0;
> where k is an array, k=200/n; and n=1:1:250.
> I tried to find the these roots using the function "fzero" but the roots of tan(), cot() involving terms is the limitation of this function. Can anyone help me to find the roots by any other available functions in MATLAB?
>
> Thank you in advance.
> ~Neil.


I don't see a problem:
%%%
k = 200/1;

f = @(x)tan(x)+k.*x;
fzero(f,10)
figure;
plot(-10:10,f(-10:10))

g = @(x)cot(x)-k.*x;
fzero(g,10)
figure
plot(0:.01:1,g(0:.01:1))
%%%
What behavior are you expecting to see that you aren't seeing?

Subject: How to find roots using similar command like "fzero"?

From: Nirmal

Date: 7 Sep, 2010 20:34:06

Message: 3 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i664rq$77t$1@fred.mathworks.com>...
> "Nirmal " <nirmal323@yahoo.com> wrote in message <i660og$rne$1@fred.mathworks.com>...
> > Hello Everyone,
> >
> > I am trying to find the roots of the following two expressions.
> > a. tan(x)+k*x=0;
> > b. cot(x)-k*x=0;
> > where k is an array, k=200/n; and n=1:1:250.
> > I tried to find the these roots using the function "fzero" but the roots of tan(), cot() involving terms is the limitation of this function. Can anyone help me to find the roots by any other available functions in MATLAB?
> >
> > Thank you in advance.
> > ~Neil.
>
>
> I don't see a problem:
> %%%
> k = 200/1;
>
> f = @(x)tan(x)+k.*x;
> fzero(f,10)
> figure;
> plot(-10:10,f(-10:10))
>
> g = @(x)cot(x)-k.*x;
> fzero(g,10)
> figure
> plot(0:.01:1,g(0:.01:1))
> %%%
> What behavior are you expecting to see that you aren't seeing?

********************************************
Hi Sean,
Actually, I have calculated the roots the two equations using mathematica with a function "findroots". The roots obtained from there and this fzero are not same.

 a. tan(x)+k*x=0;
 b. cot(x)-k*x=0;
 where k is an array, k=200/n; and n=linspace(1,200,101);
The roots of the (a) lies between m*pi+pi/2 to m*pi+pi and the roots of (b) lies between m*pi to m*pi+pi/2; m is an integer.

The roots I obtained from mathematica for m=0 and different value of k are as:
Roots of (a) Roots of (b)
    1.5740 0.0707
    1.5803 0.1220
    1.5865 0.1571
    1.5927 0.1856
    1.5988 0.2101
    1.6049 0.2319
    1.6109 0.2517
    1.6169 0.2699
    1.6229 0.2868
    1.6288 0.3027
    1.6346 0.3177
    1.6405 0.3320
    1.6462 0.3456
    1.6519 0.3585
    .... .....
   ...... .....
    2.0120 0.8443
    2.0154 0.8476
    2.0188 0.8508
    2.0221 0.8540
    2.0254 0.8572
    2.0288 0.8603

The "fzero" is giving me the similar roots like mathematica for equation(b) but is giving me zero all the time for (a).
I am expecting the roots of (a) like what I got with mathematica.
Any idea?

Thank you.

Subject: How to find roots using similar command like "fzero"?

From: Sean

Date: 7 Sep, 2010 20:59:04

Message: 4 of 4

"Nirmal " <nirmal323@yahoo.com> wrote in message <i667ju$ejl$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i664rq$77t$1@fred.mathworks.com>...
> > "Nirmal " <nirmal323@yahoo.com> wrote in message <i660og$rne$1@fred.mathworks.com>...
> > > Hello Everyone,
> > >
> > > I am trying to find the roots of the following two expressions.
> > > a. tan(x)+k*x=0;
> > > b. cot(x)-k*x=0;
> > > where k is an array, k=200/n; and n=1:1:250.
> > > I tried to find the these roots using the function "fzero" but the roots of tan(), cot() involving terms is the limitation of this function. Can anyone help me to find the roots by any other available functions in MATLAB?
> > >
> > > Thank you in advance.
> > > ~Neil.
> >
> >
> > I don't see a problem:
> > %%%
> > k = 200/1;
> >
> > f = @(x)tan(x)+k.*x;
> > fzero(f,10)
> > figure;
> > plot(-10:10,f(-10:10))
> >
> > g = @(x)cot(x)-k.*x;
> > fzero(g,10)
> > figure
> > plot(0:.01:1,g(0:.01:1))
> > %%%
> > What behavior are you expecting to see that you aren't seeing?
>
> ********************************************
> Hi Sean,
> Actually, I have calculated the roots the two equations using mathematica with a function "findroots". The roots obtained from there and this fzero are not same.
>
> a. tan(x)+k*x=0;
> b. cot(x)-k*x=0;
> where k is an array, k=200/n; and n=linspace(1,200,101);
> The roots of the (a) lies between m*pi+pi/2 to m*pi+pi and the roots of (b) lies between m*pi to m*pi+pi/2; m is an integer.
>
> The roots I obtained from mathematica for m=0 and different value of k are as:
> Roots of (a) Roots of (b)
> 1.5740 0.0707
> 1.5803 0.1220
> 1.5865 0.1571
> 1.5927 0.1856
> 1.5988 0.2101
> 1.6049 0.2319
> 1.6109 0.2517
> 1.6169 0.2699
> 1.6229 0.2868
> 1.6288 0.3027
> 1.6346 0.3177
> 1.6405 0.3320
> 1.6462 0.3456
> 1.6519 0.3585
> .... .....
> ...... .....
> 2.0120 0.8443
> 2.0154 0.8476
> 2.0188 0.8508
> 2.0221 0.8540
> 2.0254 0.8572
> 2.0288 0.8603
>
> The "fzero" is giving me the similar roots like mathematica for equation(b) but is giving me zero all the time for (a).
> I am expecting the roots of (a) like what I got with mathematica.
> Any idea?
>
> Thank you.

I'm able to replicate that behavior: no matter the initial guess - converging to 0. However, you can beat it by forcing fzero to look along a specific interval:
%%
k = 1;
f = @(x)tan(x)+k.*x;
fzero(f,[-5 -2]) %Force it to look between -5,-2
figure;
plot(-10:10,f(-10:10))

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