Approximating Function 2 Variables Differential

## Description

This interact alows the user to approximate the value of a function of 2 variables at some point using the tangent plane at some other point. The user can input the function, the point generating the tangent plane, and the range over x and y the function will be plotted on, and may use the sliders to adjust the point of approximation.

## Sage Cell

#### Code

``````x,y=var('x y')
html('<h2>Explaining approximation of a function in two \
variables by differential</h2>')
pretty_print(html('Points x0 and y0 are values where the exact value of the function \
is known. Deltax and Deltay are displacements of the new point. Exact value \
and approximation by differential at shifted point are compared.'))
@interact
def _(func=input_box('sqrt(x^3+y^3)',label="f(x,y)=",type=str), x0=1, y0=2, \
deltax=slider(-1,1,0.01,0.2),\
deltay=slider(-1,1,0.01,-0.4), xmin=0, xmax=2, ymin=0, ymax=3):
f=sage_eval('lambda x,y: ' + func)
derx(x,y)=diff(f(x,y),x)
dery(x,y)=diff(f(x,y),y)
tangent(x,y)=f(x0,y0)+derx(x0,y0)*(x-x0)+dery(x0,y0)*(y-y0)
A=plot3d(f(x,y),(x,xmin,xmax),(y,ymin,ymax),opacity=0.5)
B=plot3d(tangent(x,y),(x,xmin,xmax),(y,ymin,ymax),color='red',opacity=0.5)
C=point3d((x0,y0,f(x0,y0)),rgbcolor='blue',size=9)
CC=point3d((x0+deltax,y0+deltay,f(x0+deltax,y0+deltay)),rgbcolor='blue',size=9)
D=point3d((x0+deltax,y0+deltay,tangent(x0+deltax,y0+deltay)),rgbcolor='red',size=9)
exact_value_ori=f(x0,y0).n(digits=10)
exact_value=f(x0+deltax,y0+deltay)
approx_value=tangent(x0+deltax,y0+deltay).n(digits=10)
abs_error=(abs(exact_value-approx_value))
pretty_print(html(r'Function \$ f(x,y)=%s \approx %s \$ '%(latex(f(x,y)),latex(tangent(x,y)))))
pretty_print(html(r' \$f %s = %s\$'%(latex((x0,y0)),latex(exact_value_ori))))
pretty_print(html(r'Shifted point \$%s\$'%latex(((x0+deltax),(y0+deltay)))))
pretty_print(html(r'Value of the function in shifted point is \$%s\$'%f(x0+deltax,y0+deltay)))
pretty_print(html(r'Value on the tangent plane in shifted point is \$%s\$'%latex(approx_value)))
pretty_print(html(r'Error is \$%s\$'%latex(abs_error)))
show(A+B+C+CC+D)```
```

none

## Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

## Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.