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:
Polynomials and Linear Change of Variable

Subject: Polynomials and Linear Change of Variable

From: Bill Woessner

Date: 14 Feb, 2012 22:29:31

Message: 1 of 9

I have a polynomial, represented as a vector. So px = [3 2 1]
corresponds to p(x) = 3x^2 + 2x + 1. I would like to apply a linear
change of variable, say, y = 4x + 5. Is there an easy way to get
Matlab to apply the change of variable for me and compute the new
coefficients? In this case, I would expected to get back p(y) = 48x^2
+ 128x + 86 or py = [48 128 86]. I can think of a couple brute force
ways to do this involving conv() or pascal(). But I'm hoping there's
a fast and easy way to accomplish this.

Thanks in advance,
Bill

Subject: Polynomials and Linear Change of Variable

From: John D'Errico

Date: 15 Feb, 2012 00:21:17

Message: 2 of 9

Bill Woessner <woessner@gmail.com> wrote in message <54339d1a-198a-44dc-8608-2ebd8818c386@dq9g2000vbb.googlegroups.com>...
> I have a polynomial, represented as a vector. So px = [3 2 1]
> corresponds to p(x) = 3x^2 + 2x + 1. I would like to apply a linear
> change of variable, say, y = 4x + 5. Is there an easy way to get
> Matlab to apply the change of variable for me and compute the new
> coefficients? In this case, I would expected to get back p(y) = 48x^2
> + 128x + 86 or py = [48 128 86]. I can think of a couple brute force
> ways to do this involving conv() or pascal(). But I'm hoping there's
> a fast and easy way to accomplish this.
 
Of course, its trivial to do symbolically. So with my
sympoly toolbox...

sympoly x y
px = 3*x^2 + 2*x + 1;
subs(px,'x',4*x + 5)
ans =
    86 + 128*x + 48*x^2

But if you want to do so the hard way, you could do
this:

y = [4 5];
py = 3*conv(y,y) + 2*conv([0 1],y) + 1*conv([0 1],[0 1])
py =
    48 128 86

John

Subject: Polynomials and Linear Change of Variable

From: Nasser M. Abbasi

Date: 15 Feb, 2012 01:26:50

Message: 3 of 9

On 2/14/2012 4:29 PM, Bill Woessner wrote:
> I have a polynomial, represented as a vector. So px = [3 2 1]
> corresponds to p(x) = 3x^2 + 2x + 1. I would like to apply a linear
> change of variable, say, y = 4x + 5. Is there an easy way to get
> Matlab to apply the change of variable for me and compute the new
> coefficients? In this case, I would expected to get back p(y) = 48x^2
> + 128x + 86 or py = [48 128 86]. I can think of a couple brute force
> ways to do this involving conv() or pascal(). But I'm hoping there's
> a fast and easy way to accomplish this.
>
> Thanks in advance,
> Bill

for these things, might be easier to use symbolic tools

--------------------------
EDU>> syms x y
p=3*x^2+2*x+1;
p=expand(subs(p,x,4*x + 5))
coeff=sym2poly(p)
-----------------------
p =
  
48*x^2 + 128*x + 86
  

coeff =

     48 128 86


--Nasser

Subject: Polynomials and Linear Change of Variable

From: Roger Stafford

Date: 15 Feb, 2012 01:29:18

Message: 4 of 9

Bill Woessner <woessner@gmail.com> wrote in message <54339d1a-198a-44dc-8608-2ebd8818c386@dq9g2000vbb.googlegroups.com>...
> I have a polynomial, represented as a vector. So px = [3 2 1]
> corresponds to p(x) = 3x^2 + 2x + 1. I would like to apply a linear
> change of variable, say, y = 4x + 5. Is there an easy way to get
> Matlab to apply the change of variable for me and compute the new
> coefficients?
- - - - - - - -
  The following is valid for any degree polynomial. Let p be the set of original coefficients, in this case p = [3,2,1]. Let n be the length of p. Let the transformation be y = a*x+b.

 t = flipud(fliplr(pascal(n)).*toeplitz([p(1),zeros(1,n-1)],p));
 q = a.^(n-1:-1:0).*(b.^(n-1:-1:0)*t);

The vector q will be the new set of coefficients for powers of x.

Roger Stafford

Subject: Polynomials and Linear Change of Variable

From: Nasser M. Abbasi

Date: 15 Feb, 2012 01:30:25

Message: 5 of 9

On 2/14/2012 7:26 PM, Nasser M. Abbasi wrote:

> for these things, might be easier to use symbolic tools
>
> --------------------------
> EDU>> syms x y
> p=3*x^2+2*x+1;
> p=expand(subs(p,x,4*x + 5))
> coeff=sym2poly(p)
> -----------------------
> p =
>
> 48*x^2 + 128*x + 86
>
>
> coeff =
>
> 48 128 86

to OP, you do not need the expand() in there, I just
added it to show you that you get the same expression
as you showed.

If you adopt this, you should remove the expand()
call to make it more efficient as not needed.

--Nasser

Subject: Polynomials and Linear Change of Variable

From: Bill Woessner

Date: 15 Feb, 2012 19:36:18

Message: 6 of 9

On Feb 14, 8:29 pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
>  t = flipud(fliplr(pascal(n)).*toeplitz([p(1),zeros(1,n-1)],p));
>  q = a.^(n-1:-1:0).*(b.^(n-1:-1:0)*t);

Wow... that is simply incredible. Thank you so much. How on Earth
did you come up with that? This is along the lines of what I was
thinking, but I wasn't even close to coming up with toeplitz().

Again, thank you very much.

--Bill

Subject: Polynomials and Linear Change of Variable

From: Bruno Luong

Date: 15 Feb, 2012 20:39:12

Message: 7 of 9

Another way:

x = 0:length(px)
polyfit((x-5)/4,polyval(px,x),length(px)-1)

% Bruno

Subject: Polynomials and Linear Change of Variable

From: Roger Stafford

Date: 15 Feb, 2012 21:38:10

Message: 8 of 9

Bill Woessner <woessner@gmail.com> wrote in message <aac4275e-0e67-42b7-b662-18cd9536516f@hs8g2000vbb.googlegroups.com>...
> On Feb 14, 8:29 pm, "Roger Stafford"
> <ellieandrogerxy...@mindspring.com.invalid> wrote:
> >  t = flipud(fliplr(pascal(n)).*toeplitz([p(1),zeros(1,n-1)],p));
> >  q = a.^(n-1:-1:0).*(b.^(n-1:-1:0)*t);
>
> Wow... that is simply incredible. Thank you so much. How on Earth
> did you come up with that? This is along the lines of what I was
> thinking, but I wasn't even close to coming up with toeplitz().
>
> Again, thank you very much.
>
> --Bill
- - - - - - - - -
  You may prefer to use the following. Instead of twice flipping the entire n by n matrix output of 'pascal', it flips only the smaller p and q vectors. Consequently it uses 'hankel' instead of 'toeplitz'.

 t = b.^(0:n-1)*(pascal(n).*hankel(fliplr(p),[p(1),zeros(1,n-1)]));
 q = fliplr(a.^(0:n-1).*t);

Roger Stafford

Subject: Polynomials and Linear Change of Variable

From: Bruno Luong

Date: 15 Feb, 2012 23:34:11

Message: 9 of 9

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message

> x = 0:length(px)
> polyfit((x-5)/4,polyval(px,x),length(px)-1)

May be this modified command is clearer:

x = 0:length(px)
polyfit(x,polyval(px,4*x+5),length(px)-1)

% Bruno

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