Graviton
Graviton

Reputation: 83254

Matlab: Polynomial Expansion Routine

In Mathematica, it's easy to expand terms like

(ax^2+bx+c)^n

But is there anyway I can do this in Matlab?

Upvotes: 1

Views: 2517

Answers (2)

user85109
user85109

Reputation:

You can also use my sympoly toolbox.

>> sympoly a b c x
>> (a*x^2+b*x+c)^3
ans =
    c^3 + 3*b*c^2*x + 3*b^2*c*x^2 + b^3*x^3 + 3*a*c^2*x^2 + 6*a*b*c*x^3 + 3*a*b^2*x^4 + 3*a^2*c*x^4 + 3*a^2*b*x^5 + a^3*x^6

Upvotes: 3

Gilead
Gilead

Reputation: 1263

For any arbitrary expression: not without the Symbolic Toolbox. http://www.mathworks.com/help/toolbox/symbolic/expand.html

However, if you wish to expand polynomials, you can use the conv function. Just run it in a loop.

a = 1;
b = 2;
c = 3;
n = 5;
soln = [a b c];
for i=1:n-1
   soln = conv(soln,[a b c]);
end 

Upvotes: 5

Related Questions