# expanding a given function as a power series?

51 views (last 30 days)
Michael Vaughan on 26 Sep 2020
Edited: Ameer Hamza on 26 Sep 2020
say I have a function, for example f(x)=x^3+2x. I want to know how take an arbitrary function like this, and for each x value supstitute , the expontential function in h. I then want to expand this newly represneted function as a power series in h, as each will equal 1+h+h^2/2+h^3/3+....
Now, I understand it will have an infinite amount of terms, so if there was a way I could pick an integer (say m) such that it only calculates this power series up to the h^m term I think that would be awesome
This is quite a big endevor for me, as I have no programming experience. Could somebody show me how to write this script?? Thank you so much I really appreciate it

Ameer Hamza on 26 Sep 2020
Edited: Ameer Hamza on 26 Sep 2020
You need the symbolic toolbox for this problem!
syms x y
f(x) = x^3+2*x;
g = f(exp(y));
g_approx = taylor(g, y, 'Order', 10)
Result
>> g_approx
g_approx =
(3937*y^9)/72576 + (6563*y^8)/40320 + (2189*y^7)/5040 + (731*y^6)/720 + (49*y^5)/24 + (83*y^4)/24 + (29*y^3)/6 + (11*y^2)/2 + 5*y + 3