Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'Finding Coefficients Again' topicStudent Support Forum > General > Archives > "Finding Coefficients Again"

Next Comment >Help | Reply To Topic
Author Comment/Response
Rob Gross
02/19/00 1:47pm

I posted a message about a month ago regarding an alternative function for finding coefficients. Someone was nice enough to reply to my first message, but it didn't quite solve my problem. So this is a ''new'' message relating to an old message.
The built in function Coefficient[exp,x] does not work for all cases that I would like it to work for. I would like to create a function coef[exp,x] that would, for example, give me these results:

coef[x^2,x] = x

coef[x^3*Sin[x]*y,x] = x^2*Sin[x]*y

coef[x^3,x^4] = 0

coef[2*x^4,x^2] = 2*x^2

The built in function returns 0 in all of these cases. I believe I know how the built in function Coefficient[exp,x] works - it looks for the head Times, and checks to see if the symbol, x, matches the symbol in expression, exp, and if they are the same returns what ever is left over. Ex:

FullForm[3*x] = Times[3,x]

Coefficient[3*x,x] = 3, because the head is Times and x = x, therefore it returns 3.

Coefficient[3*x,y] = 0, because x does not equal y, and it returns 0.


FullForm[x^2] = Power[x,2], and Coefficient[x^2,x] = 0, because there is no head of Times.

I was wondering if anyone knows an easy way of doing this or has already done this. I have started to write a function that does this, but it is very complicated, and I know there has got to be an easier way to do this.

Thank You,
Rob Gross

URL: ,

Subject (listing for 'Finding Coefficients Again')
Author Date Posted
Finding Coefficients Again Rob Gross 02/19/00 1:47pm
Re: Finding Coefficients Again P.J. Hinton 02/22/00 7:47pm
Re: Finding Coefficients Again Rob Gross 02/24/00 5:03pm
Re: Finding Coefficients Again Forum Modera... 03/04/00 11:30am
Next Comment >Help | Reply To Topic