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:
ploting a polynomial

Subject: ploting a polynomial

From: Snow White

Date: 1 Sep, 2010 13:38:20

Message: 1 of 5

Hello,

I have to observe the behavior of a polynomial:

r=((n-(1/n))^2*sin^2(t))/(2+2n^2-(n+(1/n))^2*sin^2(t)+4cos(t)(sqrt(n^2-sin^2(t))))

I have to compute the roots of n or observe the behaviour of n.
r=0:0.1:1;t=0:0.3:pi;
I have decomposed the equation as follows:

A=transpose((sin(t).^2).*(1+r)-2.*r/(4.*r).*cos(t));
B=transpose(((sin(t).^2).*(1+r))./(4.*r.*cos(t)));
C=transpose((-2.*(sin(t).^2).*(1-r)+r)./(4.*r.*cos(t)));
D=transpose((sin(t).^2));

p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];

i tried using polyval
 y=polyval(p);
??? Error using ==> polyval at 44
P must be a vector

p is a mxn matrix

i tried using poly but that requires a nxn matrix.

Can anyone tell me a way of plotting this polynomial in order to study the behaviour of n by varying r and t ?

Subject: ploting a polynomial

From: ImageAnalyst

Date: 1 Sep, 2010 14:29:11

Message: 2 of 5

polyval takes two arguments, not one like you had. One argument is
the coefficients, and the other is a list of the locations where you
want the polynomial to be evaluated at.

Subject: ploting a polynomial

From: John D'Errico

Date: 1 Sep, 2010 14:32:23

Message: 3 of 5

"Snow White" <gulesaman@gmail.com> wrote in message <i5ll0c$54f$1@fred.mathworks.com>...
> Hello,
>
> I have to observe the behavior of a polynomial:
>
> r=((n-(1/n))^2*sin^2(t))/(2+2n^2-(n+(1/n))^2*sin^2(t)+4cos(t)(sqrt(n^2-sin^2(t))))
>
> I have to compute the roots of n or observe the behaviour of n.
> r=0:0.1:1;t=0:0.3:pi;
> I have decomposed the equation as follows:
>
> A=transpose((sin(t).^2).*(1+r)-2.*r/(4.*r).*cos(t));
> B=transpose(((sin(t).^2).*(1+r))./(4.*r.*cos(t)));
> C=transpose((-2.*(sin(t).^2).*(1-r)+r)./(4.*r.*cos(t)));
> D=transpose((sin(t).^2));
>
> p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];
>
> i tried using polyval
> y=polyval(p);
> ??? Error using ==> polyval at 44
> P must be a vector
>
> p is a mxn matrix
>
> i tried using poly but that requires a nxn matrix.
>
> Can anyone tell me a way of plotting this polynomial in order to study the behaviour of n by varying r and t ?

It is not a true polynomial in n by the way, since there are
negative powers of n involved.

Use meshgrid to build a grid in n and t.

Now, use contour to plot level surfaces of

f(n,t) = ((n-(1/n))^2*sin^2(t))/(2+2n^2-(n+(1/n))^2*sin^2(t)+4cos(t)(sqrt(n^2-sin^2(t))))

at different values of r.

John

Subject: ploting a polynomial

From: Snow White

Date: 1 Sep, 2010 20:20:20

Message: 4 of 5

i didnt get that could you explain in a little more detail?
A.^2*m^4+ (2.*A.*C-1)*m^3+ ((2.*A.*B)+(C.^2)+D)*m^2+ 2.*B.*C*m+ B.^2=0
this needs to be solved for m which is dependent on r and t.

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <i5lo5n$b0d$1@fred.mathworks.com>...
> "Snow White" <gulesaman@gmail.com> wrote in message <i5ll0c$54f$1@fred.mathworks.com>...
> > Hello,
> >
> > I have to observe the behavior of a polynomial:
> >
> > r=((n-(1/n))^2*sin^2(t))/(2+2n^2-(n+(1/n))^2*sin^2(t)+4cos(t)(sqrt(n^2-sin^2(t))))
> >
> > I have to compute the roots of n or observe the behaviour of n.
> > r=0:0.1:1;t=0:0.3:pi;
> > I have decomposed the equation as follows:
> >
> > A=transpose((sin(t).^2).*(1+r)-2.*r/(4.*r).*cos(t));
> > B=transpose(((sin(t).^2).*(1+r))./(4.*r.*cos(t)));
> > C=transpose((-2.*(sin(t).^2).*(1-r)+r)./(4.*r.*cos(t)));
> > D=transpose((sin(t).^2));
> >
> > p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];
> >
> > i tried using polyval
> > y=polyval(p);
> > ??? Error using ==> polyval at 44
> > P must be a vector
> >
> > p is a mxn matrix
> >
> > i tried using poly but that requires a nxn matrix.
> >
> > Can anyone tell me a way of plotting this polynomial in order to study the behaviour of n by varying r and t ?
>
> It is not a true polynomial in n by the way, since there are
> negative powers of n involved.
>
> Use meshgrid to build a grid in n and t.
>
> Now, use contour to plot level surfaces of
>
> f(n,t) = ((n-(1/n))^2*sin^2(t))/(2+2n^2-(n+(1/n))^2*sin^2(t)+4cos(t)(sqrt(n^2-sin^2(t))))
>
> at different values of r.
>
> John

Subject: ploting a polynomial

From: Roger Stafford

Date: 1 Sep, 2010 22:15:16

Message: 5 of 5

"Snow White" <gulesaman@gmail.com> wrote in message <i5mci4$rej$1@fred.mathworks.com>...
> i didnt get that could you explain in a little more detail?
> A.^2*m^4+ (2.*A.*C-1)*m^3+ ((2.*A.*B)+(C.^2)+D)*m^2+ 2.*B.*C*m+ B.^2=0
> this needs to be solved for m which is dependent on r and t.
> .........
- - - - - - - - -
  You should understand that, as it stands, your expression is very definitely not a polynomial. With the appropriate algebraic manipulation your equation can be expressed as an equivalent eighth order polynomial equation in n, but all its odd powers will be missing, so it is fourth order in n^2. Nevertheless it will have eight roots for each pair of r and t values, though many of them may be complex-valued. There does exist an explicit expression for the four roots of any quartic (fourth order) polynomial equation (with eight corresponding roots for n) but it is rather complicated. It would probably be easier to use the 'roots' function for evaluation purposes directly on the eighth order polynomial.

  However I think John has the best idea because you would no longer need to worry about complex roots nor have to convert your equation to a polynomial in n. Just observe the contours in the three-dimensional n,t plot he is suggesting for the various levels of r. This will let you easily see the values of n that correspond to various pairs of r and t values. Note that the plot is periodic in t with a period of 2*pi, so perhaps only that range of t need be plotted.

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