Solving for the coefficients of a polynomial in matlab

40 Views Asked by At

I need to find the coefficients of a Taylor series (truncated to 21 coefficients, for practical reasons)

The Taylor polynomial $P(x)=\sum{\frac{a_n}{n!}*x^n}$ has to satisfy:

$$P(x+1)=b^{P(x)}$$

for a given constant b.

I choose to minimize this cost function:

$$\int_0^1 (P(x)-b^{P(-1+x)})^2 dx==0$$

For that purpose, I made this code:

b=2^(1/2);
lenght=20;% Polynomial truncated at 20 coefficients
Zize=[1 1+lenght];

exponent = (0:lenght);% Exponents for x in the polynomial
fact=factorial(exponent);% Factorial denominators

a = sym('a',Zize);% 20 a_n to solve for
syms x;

polinomio=sum(a./fact.*(x*ones([1 1+lenght])).^exponent)
cost=int((polinomio-b^(compose(polinomio,-1+x)))^2,x,0,1)
solution=solve(cost==0,a)

The problem is that the code hangs on the last line.

There is an error, or a faster way to calculate?

I know that $P(0)=1$, so maybe it should fix $a(1)=1$, but do not know how to set it. Maybe it hangs because the solution is indeterminate/non unique?