Post Reply 
Taylor Expansion with 2 variables
12-30-2019, 01:27 AM
Post: #1
Taylor Expansion with 2 variables
I'm sharing a little function I wrote that returns the Taylor expansion of functions of two variables. The Taylor function included in the prime only works for single variable functions.

Function definition:
PHP Code:

For example, to return the second order polynomial that approximates the function sin(2x)+cos(y) at the point x=0, y=0:
PHP Code:

You can also use this function to find the equation of the tangential plane to a surface. Since the tangential plane is a first order approximation, just set the parameter ordr to 1:
PHP Code:
will give the answer:
PHP Code:
Equate the result to 0 and you have the equation of the tangential plane.

PHP Code:
def taylor2d(ff,vars,exppt,ordr):
if (type(vars) != DOM_LIST) and (type(exppt) != DOM_LIST):
elif (len(vars) == and len(exppt) == 2):
pp seq(equal(vars[ii],exppt[ii]),ii,0,len(vars)-1)
iinnbbdd 0000
while (ii<=ordr):
bb binomial(ii,nn)/(ii!)*((vars[0]-exppt[0])**nn)*((vars[1]-exppt[1])**(ii-nn))
dd += subst(diff(diff(ff,vars[0],nn),vars[1],ii-nn),pp)*bb
if (nn==0):
ii += 1
ii 1
-= 1
return dd

Attached File(s)
.hpprgm  taylor2d.hpprgm (Size: 2.37 KB / Downloads: 4)
Find all posts by this user
Quote this message in a reply
Post Reply 

User(s) browsing this thread: 1 Guest(s)