Message Boards Message Boards

0
|
6462 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Finding Coefficients of A Non-polynomial Expression

Posted 11 years ago
Hi Guys, 

I am new to Mathematica and I am dealing with symbolic calculations. I am finding trouble finding the coefficient list for non-polynomials. For example, 
3x[1]^2+4x[1]x[2]^(-1/2)

CoefficientList only applies to polynomials. Any help for non-polynomials?

Thanks in advance

Arvind Rajan
POSTED BY: Arvind Rajan
3 Replies
Yes. This can be programmed, but how to program really would depend on how you wanted to use it.

In the case that you want to extract all of the numbers at the beginning of each term, you can run:
eq = 3 x[1]^2 + 4 x[1] x[2]^(-1/2)
(List @@ eq)[[All, 1]]
The answer is basically that you will want to become familiar with pattern matching in order to do manipulations with algebra that aren't preprogrammed into Mathematica. 
POSTED BY: Sean Clarke
Any way I can use 
{x[1],x[2]}
to extract the list of coefficients? Because I know for sure that they are the variables but I might not know their powers. I want to extract the coefficients from user's input expression

Thanks
POSTED BY: Arvind Rajan
You will need to use pattern matching to extract out the parts of the expression you want. The best function for this is Cases. For example:
Cases[3 x[1]^2 + 4 x[1] x[2]^(-1/2), cons_ x[1]^2 -> cons]
This produces 3 since 3 is result of cons_ x[1]^2 -> cons being matched.
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract