MATLAB Creating a symbolic function with matrix elements

87 Views Asked by At

I have got a matrix like

c1 = [1 2 3] or c2 = [4 2]  

Now I want to create a symbolic function with

c1 and c2 or any other matrix.

This symbolic function should look like:

c1: f(x) = 1 + 2x + 3x²
c2: f(x) = 4 + 2x  

Important: I want create this function automatically.
Is there any chance to do this nicely?

1

There are 1 best solutions below

0
On BEST ANSWER

That is exactly what the function poly2sym does. Small but important difference: you describe the following function:

a1 + a2*x + a3*x^2 + ... + an*x^n-1

while poly2sym creates a function

a1*x^n-1 + ... + an-1*x^1 + an

so you will have to flip the order of the input vector c using e.g. fliplr.

c1 = [1,2,3];
c2 = [4,2];

f1 = poly2sym(fliplr(c1))
f1 = 
   3*x^2 + 2*x + 1

f2 = poly2sym(fliplr(c2))
f2 = 
   2*x + 4