0

Heyy, I want to strech polynomes into vectors. E.g.: Example 1. (A + B)^2 = A^2 + 2AB + B^2 -> c(A^2, 2AB, C^2) Example 2. (A + B + c)^2 = A^2 + 2AB + B^2 + 2AC + C^2 + 2BC -> c(A^2 + 2AB, B^2, 2AC, C^2, 2BC) Generalised: (A + B + C + ... etc)^n = ... -> c(..,..,...etc)

So what the function should do is streching out these expressions and sore each element into a cell of a vector. It can be done by for cycle, but its needed for a fast optimisation, so a vectorized form would be needed. So the mentioned A, B, C ... are parameters.

I tried searching for a built in function, but there were't any, perhaps in a package.

I tried using the polym function, but it messed up the calculations, probably because it gave an orthogonised form.

  • 1
    Seems very similar to https://stackoverflow.com/questions/76847489/r-multinomial-formula-in-r. R itself does not really do symbolic algebra (though there are packages that can do that). It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. The `polym()` function has a `raw=TRUE` function if you don't want orthogonised coefficients. – MrFlick Aug 07 '23 at 19:28

0 Answers0