-
-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathhigh-order-linear_1.pg
More file actions
127 lines (106 loc) · 2.69 KB
/
high-order-linear_1.pg
File metadata and controls
127 lines (106 loc) · 2.69 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
## DESCRIPTION
## Differential Equations.
## ENDDESCRIPTION
## DBsubject(Differential equations)
## DBchapter(Higher order differential equations)
## DBsection(Linear, constant coefficients, homogeneous)
## Date(24/11/2015)
## Institution(METU-NCC)
## Author(Benjamin Walter)
##################################
# Initialization
DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGmatrixmacros.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
);
#####################################
# Setup
Context("Numeric");
Context()->variables->are(
r=>"Real",
t=>"Real"
);
my $a=random(-3,3,1); my $b=random(1,3,1);
my $r=non_zero_random(-3,3,1);
my @pow=([1,3,4],
[2,2,3],
[3,1,2]);
my $p=random(0,2,1);
my @soln=(); my @ok=(0,1,2,3,4,5,6,7,8);
for(my $i=0;$i<$pow[$p][0];$i++) {
push @soln, Formula("(t^$i)*e^($a t)*cos($b t)")->reduce;
push @soln, Formula("(t^$i)*e^($a t)*sin($b t)")->reduce;
}
for(my $i=0;$i<$pow[$p][1];$i++) {
push @soln, Formula("t^$i")->reduce;
}
for(my $i=0;$i<$pow[$p][2];$i++) {
push @soln, Formula("(t^$i)*e^($r t)")->reduce;
}
#############################
# answer evaluators
$ansSplice = sub {
my ($correct, $student, $answerHash) = @_; # get correct and student MathObjects
my $context = Context()->copy;
$context->flags->set(no_parameters=>0);
$context->variables->add( c=>'Parameter' );
my $c = Formula($context, 'c');
for (my $i=0; $i<scalar(@ok); $i++) {
if ( (Formula($context, "$c*$soln[$ok[$i]]") == Formula($context, "$student")) &&
(Compute(0) != $student) ) {
splice @ok,$i,1;
return 1;
}
}
return 0;
};
###########################
# problem text
$cxroot = Formula("r^2-2*$a*r+($a*$a+$b*$b)")->reduce;
$rroot = Formula("r-$r")->reduce;
$charEqn = Formula("($cxroot)^$pow[$p][0]r^$pow[$p][1]($rroot)^$pow[$p][2]")->reduce;
Context()->texStrings;
BEGIN_TEXT
A 9th order, linear, homogeneous, constant coefficient differential equation has
a characteristic equation which factors as follows.
\[ $charEqn = 0 \]
Write the nine fundamental solutions to the differential equation.
$PAR
\{ mbox( [
"$SPACE \(y_1 = \)",
ans_rule(10),
"\(\qquad y_2 = \)",
ans_rule(10),
"\(\qquad y_3 = \)",
ans_rule(10)
] ) \}
$PAR
\{ mbox( [
"$SPACE \(y_4 = \)",
ans_rule(10),
"\(\qquad y_5 = \)",
ans_rule(10),
"\(\qquad y_6 = \)",
ans_rule(10)
] ) \}
$PAR
\{ mbox( [
"$SPACE \(y_7 = \)",
ans_rule(10),
"\(\qquad y_8 = \)",
ans_rule(10),
"\(\qquad y_9 = \)",
ans_rule(10)
] ) \}
$PAR
(You can enter your answers in any order.)
END_TEXT
Context()->normalStrings;
$showPartialCorrectAnswer=1;
for(my $i=0; $i<9; $i++) {
ANS( Formula("$soln[$i]")->cmp(checker => $ansSplice) );
}
ENDDOCUMENT();