-
-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathbvp.pg
More file actions
161 lines (126 loc) · 3.87 KB
/
bvp.pg
File metadata and controls
161 lines (126 loc) · 3.87 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
## DBsubject(Differential equations)
## Date(20/12/2015)
## Institution(METU-NCC)
## Author(Benjamin Walter)
## Level(5)
## TitleText1('Differential Equations')
## KEYWORDS('ODE', 'boundary value')
########################################################################
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"answerHints.pl",
"parserMultiAnswer.pl",
"unionLists.pl",
"PGchoicemacros.pl",
"contextFraction.pl"
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
##############################################################
#
# Setup
#
#
Context("Numeric");
Context()->variables->{namePattern} = qr/[a-z][a-z0-9_]*'*/i;
Context()->variables->are(
"y"=>"Real","y'"=>"Real","y''"=>"Real");
$DEcontext = Context()->copy;
Context("Numeric");
Context()->variables->are(
"x"=>"Real",
"n"=>["Real",limits=>[1,6],resolution=>1],
"a"=>"Real","b"=>"Real","c"=>"Real","d"=>"Real");
Context()->strings->add(
"No Solution"=>{alias=>"DNE"},
"No Solutions"=>{alias=>"DNE"});
$Default = Context()->copy;
###########
##
## Differential equation
my $beta = random(1,5,1); # frequency for solutions
my @n = (random(1,min($beta*3,10),1), # right boundary time
random(1,min($beta*3,10),1), # $t = $n (pi / $beta)
random(0,min($beta*3,10),1)); # (2$n+1)/2 (pi / $beta)
Context("Fraction"); # right boundary times $t = $a/$b
my @a,@b; # -- try to convert to pretty fractions
@t = (Fraction("($n[0])/$beta"),
Fraction("($n[1])/$beta"),
Fraction("((2*$n[2]+1))/(2*$beta)"));
for(my $i=0;$i<3;$i++) {($a[$i],$b[$i]) = $t[$i]->value;}
@t = (Formula("$a[0]*pi/$b[0]")->reduce,
Formula("$a[1]*pi/$b[1]")->reduce,
Formula("$a[2]*pi/$b[2]")->reduce);
Context("Numeric");
$y0 = random(-3,3,1); # left boundary value y(0)
if ($y0 == 0) {
@BV = (0,
non_zero_random(-3,3,1),
random(-3,3,1));
} else {
@BV = (($n[0]%2==0) ? $y0 : -$y0,
($n[1]%2==0) ? -$y0 : $y0,
non_zero_random(-1,1,1)*$y0);
}
my $s = ($n[2]%2==0) ? 1 : -1; # is sin($t[2]*$beta) = 1 or -1 ?
$DE = Formula($DEcontext, "y'' + $beta^2 y")->reduce;
@soln = (Formula($Default, "$y0*cos($beta x) + c sin($beta x)"),
Formula($Default, "DNE"),
Formula($Default, "$y0*cos($beta x) + $s*$BV[2]*sin($beta x)"));
@mix = NchooseK(3,3);
###########
##
## Text
Context()->texStrings;
BEGIN_TEXT
Solve the following differential equation with the given boundary
conditions.
$BR $SPACE $SPACE
- If there are infinitely many solutions, use ${BBOLD}c${EBOLD} for any
undetermined constants.
$BR $SPACE $SPACE
- If there are no solutions, write ${BBOLD}No Solution${EBOLD}.
$BR $SPACE $SPACE
- Write answers as functions of \(x\) (i.e. \(y=y(x)\)).
$PAR
\[\displaystyle $DE = 0 \]
$PAR
\{ BeginList('UL') \}
$ITEM
$BBOLD A) $EBOLD $SPACE $SPACE Boundary conditions:
\(\displaystyle \quad \begin{aligned}[t]
y(0) &= $y0 \\
y\left($t[$mix[0]]\right) &= $BV[$mix[0]]
\end{aligned} \)
$PAR $SPACE $SPACE
\(y = \) \{ ans_rule(40) \}
$ITEMSEP
$ITEM
$BBOLD B) $EBOLD $SPACE $SPACE Boundary conditions:
\(\displaystyle \quad \begin{aligned}[t]
y(0) &= $y0 \\
y\left($t[$mix[1]]\right) &= $BV[$mix[1]]
\end{aligned} \)
$PAR $SPACE $SPACE
\(y = \) \{ ans_rule(40) \}
$ITEMSEP
$ITEM
$BBOLD C) $EBOLD $SPACE $SPACE Boundary conditions:
\(\displaystyle \quad \begin{aligned}[t]
y(0) &= $y0 \\
y\left($t[$mix[2]]\right) &= $BV[$mix[2]]
\end{aligned} \)
$PAR $SPACE $SPACE
\(y = \) \{ ans_rule(40) \}
\{ EndList('UL') \}
END_TEXT
Context()->normalStrings;
##############
##
## Answers
ANS($soln[$mix[0]]->cmp);
ANS($soln[$mix[1]]->cmp);
ANS($soln[$mix[2]]->cmp);
ENDDOCUMENT();