-
-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathbvp-eigen.pg
More file actions
126 lines (91 loc) · 2.77 KB
/
bvp-eigen.pg
File metadata and controls
126 lines (91 loc) · 2.77 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
## 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",
"unionLists.pl",
"PGchoicemacros.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",
"lambda"=>"Real");
Context()->variables->set(lambda => {TeX => '{\lambda}'});
$DEcontext = Context()->copy;
Context("Numeric");
Context()->variables->are(
"x"=>"Real",
"n"=>["Real",limits=>[1,6],resolution=>1]);
$Default = Context()->copy;
Context()->variables->remove("x");
$Default_nox = Context()->copy;
###########
##
## Differential equation
$DE = Formula($DEcontext, "y'' + lambda y")->reduce;
$L = random(1,6,1); # length of interval
@d = (random(0,1,1), # left boundary has derivative
random(0,1,1)); # right boundary has derivative
$y0 = ($d[0]==0) ? Formula($DEcontext, "y") :
Formula($DEcontext, "y'") ;
$y1 = ($d[1]==0) ? Formula($DEcontext, "y") :
Formula($DEcontext, "y'") ;
$alpha = (($d[0]==$d[1])) ? Formula($Default_nox,"(n*pi)/$L") :
Formula($Default_nox,"((2*n+1)*pi)/(2*$L)") ;
$lambda = Formula($Default_nox,"$alpha^2");
$f = ($d[0]==0) ? Formula($Default,"sin($alpha*x)") :
Formula($Default,"cos($alpha*x)") ;
###########
##
## Text
Context()->texStrings;
BEGIN_TEXT
Find the eigenvalues and eigenfunctions for the following boundary value problem
(with \(\lambda > 0\)).
$PAR
\[\displaystyle $DE = 0
\qquad \mathrm{with} \quad
$y0(0) = 0, \quad $y1($L) = 0. \]
$PAR
Eigenvalues: \(\quad \,\,\lambda_n = \)\{ ans_rule(20) \} $PAR
Eigenfunctions: \(\ \ y_n = \)\{ ans_rule(20) \} $PAR
$SPACE $SPACE ${BBOLD}Notation:${EBOLD} Your answers should involve \(n\) and \(x\).
END_TEXT
$showHint = 2;
BEGIN_TEXT
$BR
$HR
$PAR
If you don't get this in $showHint tries, you can get a hint.
END_TEXT
BEGIN_HINT
When computing eigenvalues, the following two formulas may be useful:$PAR
$SPACE $SPACE
\(\sin(\theta) = 0\) when \(\displaystyle \theta = n\pi\). $BR
$SPACE $SPACE
\(\cos(\theta) = 0\) when \(\displaystyle \theta = \frac{(2n+1)\pi}{2}\).
END_HINT
Context()->normalStrings;
##############
##
## Answers
ANS($lambda->cmp());
ANS($f->cmp());
COMMENT("Randomly picks L. Randomly takes derivatives on left and right boundary values.");
ENDDOCUMENT();