/
tangent-plane.pg
70 lines (58 loc) · 1.78 KB
/
tangent-plane.pg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
## Template for calling Sage from within a WebWork pg file
## BEGIN_DESCRIPTION
## Sample problem embedding Sage in WW
## END_DESCRIPTION
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
);
###############################################
##
## pg initializations and regular WeBWorK code
Context("Matrix");
$SageCode1=<<END;
def func(arg):
f = choice([sin,cos,log,exp])
return f(arg)
def term(*vars):
varchoices = [[v^k for k in range(1,3)] for v in vars]
varchoices.append(range(1,10))
return prod(choice(i) for i in varchoices)
f(x,y) = func(term(x))+term(x,y)
WEBWORK={}
WEBWORK['f']=f(x,y)
WEBWORK['fdiff']=f.diff()(x,y)
WEBWORK['fdiff2']=f.diff(2)(x,y)
WEBWORK['estimate'] = f.diff()(1,2)*vector([0.1,-.2])
WEBWORK['tanplane'] = f(1,2).n()+f.diff()(1,2).n()*vector([x-1,y-2])
END
# accepted_tos=>true indicates that you agree to the terms of service:
# https://sagecell.sagemath.org/tos.html
$reply = AskSage($SageCode1,{seed=>$problemSeed, accepted_tos=>true});
$f = Formula($reply->{f});
$fdiff = Matrix([$reply->{fdiff}]);
$fdiff2 = Matrix($reply->{fdiff2});
$estimate = Formula($reply->{estimate});
$tanplane = Formula($reply->{tanplane});
Context()->texStrings;
BEGIN_TEXT
Let \(f(x,y)=$f\). Find the following derivatives.
$BR
$BR
\(Df(x,y)=\)\{ $fdiff->ans_array(50)\}
$BR
$BR
The second derivative \(D^2f(x,y)=\)\{$fdiff2->ans_array(50)\}
$BR
$BR
Suppose you are at \((x,y)=(1,2)\) and you want to move to \((x,y)=(1.1,1.8)\). Use the derivative of \(f\) to estimate how much \(f(x,y)\) changes in that move: \(df=\)\{ans_rule(10)\}.
$BR
Find the equation of the tangent plane to \(f(x,y)\) at \((x,y)=(1,2)\): \(z=\)\{ans_rule(30)\}.
END_TEXT
Context()->normalStrings;
ANS($fdiff->cmp);
ANS($fdiff2->cmp);
ANS($estimate->cmp);
ANS($tanplane->cmp);
ENDDOCUMENT();