Re: Generate polynomial of specified degree
- To: mathgroup at smc.vnet.net
 - Subject: [mg60656] Re: [mg60618] Generate polynomial of specified degree
 - From: János <janos.lobb at yale.edu>
 - Date: Fri, 23 Sep 2005 04:20:04 -0400 (EDT)
 - References: <200509220608.CAA01863@smc.vnet.net>
 - Sender: owner-wri-mathgroup at wolfram.com
 
On Sep 22, 2005, at 2:08 AM, Renan wrote:
> Hello,
>
> Sorry if this may seem a silly question, but I readed the Mathematica
> help and found no references.
>
> Is there any function that can generate a polynomial of a given  
> degree?
>
> e.g.
>
> For degree 1, f[x] would return a x + b
> For degree 2, f[x] would return a x^2 + b x + c (quadratic equation)
> For degree 3, f[x] would return a x^3 + b x^2 + c x + d (quadratic  
> equation)
>
> Thanks,
> Renan - Canoas, RS, Brazil
>
I do not know about function, but here is a newbie approach.
In[1]:=
n = 5;
In[2]:=
coef = Table[ToExpression[
     StringJoin["a",
      ToString[i]]], {i, 0, n}]
Out[2]=
{a0, a1, a2, a3, a4, a5}
In[4]:=
var = Table[x^i, {i, 0, n}]
Out[4]=
{1, x, x^2, x^3, x^4, x^5}
In[5]:=
Inner[Times, var, coef, Plus]
Out[5]=
a0 + a1*x + a2*x^2 + a3*x^3 +
   a4*x^4 + a5*x^5
I am sure there is a more elegantus way to to this
János
--------------------------------------------
f @@ # & /@ ===  f @@@
- References:
- Generate polynomial of specified degree
- From: Renan <renan.birck@gmail.com>
 
 
 - Generate polynomial of specified degree