User Tools

Site Tools


public:mathematica_common_expressions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
public:mathematica_common_expressions [2016/10/10 11:46] – created Fufu Fangpublic:mathematica_common_expressions [2018/03/31 00:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== Mathematica Common Expressions ======
 +===== Taylor Series =====
 +The $n^th$ term of the Taylor series expansion for the function $f(x)$ at $a$ can be obtained by the following function: 
 +<code mathematica>
 +TaylorTerm[fx_, x_, a_, n_] := (((Evaluate[D[fx, {x, n}]]) /. x -> a)/n!) (x - a)^n
 +</code>
  
 +The sum of the first n terms for the Taylor series expansion for the function $f(x) at $a$ can be obtained by the following function:
 +<code mathematica>
 +TaylorSeries[fx_, x_, a_, n_] :=  Evaluate[Normal[Series[fx[y], {y, a, n}]]] /. y -> x
 +</code>
 +Note that you may have to use a pure function as the first argument, e.g.
 +<code mathematica>
 +In[1]:= TaylorSeries[Function[x, Sqrt[x + 1]], x, 0, 10]
 +Out[1]= 1 + x/2 - x^2/8 + x^3/16 - (5 x^4)/128 + (7 x^5)/256 - (
 + 21 x^6)/1024 + (33 x^7)/2048 - (429 x^8)/32768 + (715 x^9)/65536 - (
 + 2431 x^10)/262144
 +</code>
public/mathematica_common_expressions.1476099985.txt.bz2 · Last modified: 2018/03/31 00:38 (external edit)