Re: change of a coefficient in a polynomial
- To: mathgroup at smc.vnet.net
- Subject: [mg44789] Re: change of a coefficient in a polynomial
- From: drbob at bigfoot.com (Bobby R. Treat)
- Date: Thu, 27 Nov 2003 11:38:13 -0500 (EST)
- References: <bpurvg$oc7$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
I don't know if this is the obvious solution you don't want, or the
more flexible solution you DO want. Neither, maybe!
ClearAll[changeCoefficient]
changeCoefficient[poly_, x_, n_, target_] :=
Collect[poly + (target[Coefficient[poly, x]] -
Coefficient[poly, x, n])*x^n, x]
p[x_] := c[0] + c[1]*x + c[2]*x^2
changeCoefficient[p[x], x, 0, -# &]
changeCoefficient[p[x], x, 0, 1 &]
changeCoefficient[p[x], x, 2, Sin]
changeCoefficient[p[x], x, 3, Sin]
-c[1] + x*c[1] + x^2*c[2]
1 + x*c[1] + x^2*c[2]
c[0] + x*c[1] + x^2*Sin[c[1]]
c[0] + x*c[1] + x^2*c[2] + x^3*Sin[c[1]]
Bobby
Paolo Bientinesi <pauldj at cs.utexas.edu> wrote in message news:<bpurvg$oc7$1 at smc.vnet.net>...
> Second question about polynomials:
>
> assume you are given a polynomial
>
> p[x_] := c[0] + c[1] x + c[2] x^2 ....
>
> and you want to generate a polynomial p1[x] from p[x]
> changing one coefficient only, like:
>
> p1[x_] := -c[0] + c[1] x + c[2] x^2
>
>
> Is there any other way other than the obvious CoefficientList
> solution?
>
> Thanks