-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodingProblem9.pg
More file actions
107 lines (87 loc) · 2.38 KB
/
CodingProblem9.pg
File metadata and controls
107 lines (87 loc) · 2.38 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
##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",
"parserPopUp.pl"
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
# How many attempts before a hint?
$showHint = 5;
#Allow the student to generate a new (re-randomized) problem
#AFTER they have submitted a correct answer.
ProblemRandomize(onlyAfterDue=>0);
##############################################################
$r = random(0.1,0.9,0.01);
$b = random(0.2,2,0.1);
$a0 = random(2,10,1);
$N = random(50,100,1);
$popup1 = PopUp(["?","A","b","r","n","N"],"N");
$popup2 = PopUp(["?","A","b","r","n","N"],"A");
$popup3 = PopUp(["?","A","b","r","n","N"],"n");
$popup4 = PopUp(["?","A","b","r","n","N"],"A");
$ae = $b / (1-$r);
##############################################################
#
# Text
#
#
Context()->texStrings;
BEGIN_TEXT
Consider the sequence \( a_{n+1} = $r a_n + $b\) with initial condition \( a_0 = $a0 \). Fill in the blanks in the MATLAB code that will create a plot of this discrete sequence for \(n=0,1,2,\ldots,$N\).
$PAR
clear; clc; clf; $BR
r = \{ans_rule(5)\}; $BR
b = \{ans_rule(5)\}; $BR
A = \{ans_rule(5)\}; $BR
plot(0,A,'b*'); $BR
hold on $BR
N = \{ans_rule(5)\}; $BR
for n = 1:\{ $popup1->menu() \}; $BR
A = r * \{$popup2->menu()\}+b; $BR
plot(\{$popup3->menu()\},\{$popup4->menu()\},'b*') $BR
end
$PAR
Now find the equilibrium value for this linear difference equation. $BR
\(a_{eq} = \) \{ans_rule(10)\}
END_TEXT
ANS(num_cmp($r,tol=>0.5));
ANS(num_cmp($b,tol=>0.5));
ANS(num_cmp($a0,tol=>0.5));
ANS(num_cmp($N,tol=>0.5));
ANS( $popup1->cmp());
ANS( $popup2->cmp());
ANS( $popup3->cmp());
ANS( $popup4->cmp());
ANS(num_cmp($ae,tol=>0.01));
##############################################################
#
# Answers
#
#
ENDDOCUMENT();