-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewton2.pg
More file actions
89 lines (66 loc) · 1.71 KB
/
Newton2.pg
File metadata and controls
89 lines (66 loc) · 1.71 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
84
85
86
87
88
89
##DESCRIPTION
## This problem is meant to have students write brief pieces of code to solve problems that have a specific numerical answer.
##ENDDESCRIPTION
##KEYWORDS('programming', 'code')
## DBsubject('Programming')
## DBchapter('')
## DBsection('')
## Date('6/7/2016')
## Author('')
## Institution('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
########################################################################
DOCUMENT();
loadMacros(
"PG.pl",
"PGauxiliaryFunctions.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"MathObjects.pl",
"problemRandomize.pl",
"PGanswermacros.pl",
"PGgraphmacros.pl",
"PGnumericalmacros.pl",
"PGstatisticsmacros.pl",
"answerHints.pl"
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
# How many attempts before a hint?
$showHint = 10;
#Allow the student to generate a new (re-randomized) problem
#AFTER they have submitted a correct answer.
ProblemRandomize(onlyAfterDue=>0);
##############################################################
$a = random(2,9);
$b = random(2,9);
$c = random(2,19);
$x0 = random(5,15);
$N = random(8,15);
$xn = $x0;
for ( $j = 1; $j <= $N; $j++) {
$xn = $xn - ( $a*exp($b *$xn) -$c) / ( $a*$b*exp($b *$xn) );
}
##############################################################
#
# Text
#
#
Context()->texStrings;
BEGIN_TEXT
Write a Matlab program to apply Newton's method for root finding to the function \( f(x) = $a e^{$b x} -$c\) starting with the number \( x_0 = $x0 \). If we take $N steps, what value do we get for \(x_{$N}\)?
$PAR
\{ans_rule(15)\}
$PAR
END_TEXT
ANS(num_cmp($xn,tol=>0.001));
##############################################################
#
# Answers
#
#
ENDDOCUMENT();