-
-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathBCIT_chyn.pg
More file actions
83 lines (76 loc) · 2.16 KB
/
BCIT_chyn.pg
File metadata and controls
83 lines (76 loc) · 2.16 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
# DESCRIPTION
# WeBWorK problem written by Stefan Lukits
# <slukits(at)bcit(dot)ca>
# DBsubject(Calculus - single variable)
# DBchapter(Applications of differentiation)
# DBsection)(Newton's method)
# Date(2020/04/02)
# Institution(British Columbia Institute of Technology)
# Author(Stefan Lukits)
# KEYWORDS('Newtons method')
# supported by the BCcampus Open Homework Systems Project Grant
DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGchoicemacros.pl",
"MathObjects.pl",
"PGgraphmacros.pl",
"unionTables.pl",
"PGcourse.pl",
"RserveClient.pl"
);
### Random number generator seed based on student's login. No need to change.
Context("Numeric")->variables->are(t=>"Real");
$c=random(1.1,1.9,0.1);
$k=random(0.2,0.9,0.1);
$sol="0";
$best=(-10)-$c-$k*sin(-10);
$absbest=abs($best);
$bestindex=0;
for ($i1=0;$i1<=20;++$i1)
{
$x=$i1-10;
$posa=$x-$c-$k*sin($x);
$absposa=abs($posa);
if ($absposa<$absbest)
{
$best=$posa;
$absbest=$absposa;
$bestindex=$i1;
}
}
$bestnum=$bestindex-10;
$bestnummo=$bestnum-1;
$bestnumpo=$bestnum+1;
$x0=$bestnum;
$x1=$x0-(($x0-1.6-0.2*sin($x0))/(1-0.2*cos($x0)));
$x2=$x1-(($x1-1.6-0.2*sin($x1))/(1-0.2*cos($x1)));
$gr = init_graph($bestnummo,-1,$bestnumpo,1,axes=>[0,0],grid=>[4,4],size=>[300,300]);
add_functions($gr,"x-$c-$k*sin(x) for x in <$bestnummo,$bestnumpo> using color:blue and weight:2");
TEXT(beginproblem());
Context()->texStrings;
BEGIN_TEXT
To calculate a planet's space coordinates, we have to solve equations like
\[ x=$c+$k\sin{}x \]
$BCENTER
\{ image( insertGraph($gr),
width=>200,height=>200,tex_size=>800 ) \}
$BR
(Click on graph to enlarge)
$ECENTER
\(x_{0}=$bestnum\) is a decent first approximation. Use two applications of Newton's method to improve this estimate. That is, start with \(x_{0}\) and find both \(x_{1}\) and \(x_{2}\). Make sure to show all of your steps.
$PAR
\(x_{1}=\)\{ ans_rule(10) \}
$BR
\(x_{2}=\)\{ ans_rule(10) \}
END_TEXT
Context()->normalStrings;
ANS(num_cmp($x1));
ANS(num_cmp($x2));
Context()->texStrings;
SOLUTION(EV3(<<'END_SOLUTION'));
$PAR SOLUTION $PAR
Use \(x_{n+1}=x_{n}-\frac{x_{n}-$c-$k\sin{}x_{n}}{1-$k\cos{}x_{n}}\) for \(x_{1}=$x1\) and \(x_{2}=$x2\).
END_SOLUTION
Context()->normalStrings;
ENDDOCUMENT();