-
-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy path3x3-system-convert.pg
More file actions
152 lines (120 loc) · 3.27 KB
/
3x3-system-convert.pg
File metadata and controls
152 lines (120 loc) · 3.27 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
## DESCRIPTION
## Differential Equations.
## ENDDESCRIPTION
## DBsubject(Differential equations)
## DBchapter(Systems of differential equations)
## DBsection(Reduction to first order systems)
## Institution(METU-NCC)
## KEYWORDS('differential equation' 'first order' 'matrices')
DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGmatrixmacros.pl",
"PGbasicmacros.pl", # needed for answer_matrix
"MathObjects.pl",
"parserMultiAnswer.pl",
"answerHints.pl",
);
Context("Numeric");
Context()->variables->{namePattern} = qr/[a-z][a-z0-9_]*'*/i;
Context()->variables->are(
t=>"Real",
y=>"Real",
"y'"=>"Real",
"y''"=>"Real",
"y'''"=>"Real",
"x1"=>"Real",
"x2"=>"Real",
"x3"=>"Real"
);
sub random_F {
my $myF;
my $c = non_zero_random(-3,3,1);
if (random(0,2,1)) {
my $max_n = random(1,4,1);
my $terms = random(1,min($max_n,3),1);
$myF = "$c t^$max_n";
my @all_n = (0 .. ($max_n-1));
for (my $i=1; $i<$terms; $i++) {
$c = non_zero_random(-3,3,1);
my $n = splice(@all_n,random(0,@all_n-1,1),1);
$myF = $myF . " + $c t^$n";
}
} else {
if (random(0,1,1)) {
$myF = "$c cos(t)";
} else {
$myF = "$c sin(t)";
}
}
return Formula("$myF")->reduce;
}
my $p0, $p1, $p2, $p3, $g;
$p0=non_zero_random(-4,4,1);
# $p0 = random_F();
$p2 = random_F();
$g = random_F();
if (random(0,1,1)) { $p1=random_F(); }
else { $p1 = Formula("0"); }
if (random(0,1,1)) { $p3=random_F(); }
else { $p3 = Formula("0"); }
$t0 = random(-3,3,1);
$y0 = random(-3,3,1); $yp0 = random(-3,3,1); $ypp0 = random(-3,3,1);
$Diff_Eq = Formula("$p0 y''' + $p1 y'' + $p2 y' + $p3 y ")->reduce;
Context()->noreduce('(-x)-y','(-x)+y');
$Diff_Eq_r1 = Formula(" - ($p3 / $p0) y - ($p2 / $p0) y' - ($p1 / $p0) y'' + ($g / $p0)")->reduce;
$Diff_Eq_r2 = Formula(" - ($p3 / $p0) x1 - ($p2 / $p0) x2 - ($p1 / $p0) x3 + ($g / $p0)")->reduce;
Context()->texStrings;
BEGIN_TEXT
Write the given third order linear equation as an equivalent system
of first order equations with initial values.
\[ $Diff_Eq = $g \\
{\ }\qquad \qquad \mathrm{with}\qquad
y($t0)=$y0,\ \ y'($t0)=$yp0,\ \ y''($t0)=$ypp0 \]
Use \(x_1 = y\), \(x_2 = y'\), and \(x_3 = y''\).
$PAR
\{ mbox(
"\( \displaystyle \boldsymbol{\vec{x}\,'} = \)",
answer_matrix(3,3,10),
"\( \displaystyle \boldsymbol{\vec{x}} \) + ",
answer_matrix(3,1,10)
) \}
$BR
with initial values
\{ mbox(
"\(\qquad \boldsymbol{\vec{x}} \biggl( \)",
ans_rule(5),
"\( \biggr) = \)",
answer_matrix(3,1,5)
) \}
END_TEXT
$showHint = 2;
BEGIN_TEXT
$PAR
If you don't get this in $showHint tries, you can get a hint.
END_TEXT
BEGIN_HINT
$PAR
The differential equation can be rewritten as
\[ \bigl(y''\bigr)' = $Diff_Eq_r1 \]
i.e.
\[ x_3' = $Diff_Eq_r2 \]
$PAR
Combine this with the fact that
\(x_1' = y' = x_2\), etc. to get the complete system.
END_HINT
Context()->normalStrings;
$showPartialCorrectAnswer=1;
ANS(Real("0")->cmp);ANS(Real("1")->cmp);ANS(Real("0")->cmp);
ANS(Real("0")->cmp);ANS(Real("0")->cmp);ANS(Real("1")->cmp);
ANS(Formula("-$p3/$p0")->cmp);
ANS(Formula("-$p2/$p0")->cmp);
ANS(Formula("-$p1/$p0")->cmp);
ANS(Real("0")->cmp);
ANS(Real("0")->cmp);
ANS(Formula("$g/$p0")->cmp);
ANS(Real("$t0")->cmp);
ANS(Real("$y0")->cmp);
ANS(Real("$yp0")->cmp);
ANS(Real("$ypp0")->cmp);
ENDDOCUMENT();