-
-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathlaplace-inv_random.pg
More file actions
208 lines (149 loc) · 5.31 KB
/
laplace-inv_random.pg
File metadata and controls
208 lines (149 loc) · 5.31 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
##DESCRIPTION
## Laplace transforms: inverse laplace
##ENDDESCRIPTION
## DBsubject(Differential equations)
## DBchapter(Laplace transforms)
## DBsection(Step functions)
## Institution(METU-NCC)
## Date (11/01/2016)
## Author (Benjamin Walter)
## Level(5)
## KEYWORDS('Laplace transform')
###################################################
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGunion.pl",
"answerHints.pl",
"parserAssignment.pl",
"parserFunction.pl"
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
###################################################
##
## Setup Contexts
Context("Numeric");
Context()->variables->are(
"t"=>"Real");
Context()->functions->add(
step => {
class => 'Parser::Legacy::Numeric',
perl => 'Parser::Legacy::Numeric::do_step'
});
parserFunction("u(t)" => "1 - 1*step(-1*t)");
$f_t = Context()->copy;
Context("Numeric");
Context()->variables->are(
"s"=>"Real", "A"=>"Real", "B"=>"Real");
Context()->noreduce("(-x)+y","(-x)-y");
$F_pf = Context()->copy;
Context("Numeric");
Context()->variables->are(
"s"=>"Real");
Context()->noreduce("(-x)-y");
$F_s = Context()->copy;
###################################################
##
## Setup Functions
$type = random(1,3,1); # Type I, II, or III
$a = non_zero_random(-4,4,1); # roots
$b = non_zero_random(-4,4,1);
$c = random(2,6,1); # exp - step
$A = non_zero_random(-2,2,1); # partial fractions
$B = non_zero_random(-2,2,1); # / coefficients
if ($type==1) { # Type I partial fractions
do { $b = non_zero_random(-4,4,1); }
while ($a == $b);
$num = Formula($F_s, "($A+$B) s - ($A*$b + $B*$a)")->reduce;
$den = Formula($F_s, "s^2 - ($a+$b)s + ($a*$b)")->reduce;
$yt = Formula($f_t, "u(t-$c) ( $A*e^($a*(t-$c)) + $B*e^($b*(t-$c)) )")->reduce;
} elsif ($type==2) { # Type II partial fractions
$b = $a;
$num = Formula($F_s, "$B s + ($A - $B*$a)")->reduce;
$den = Formula($F_s, "s^2 - 2*$a s + $a*$a")->reduce;
$yt = Formula($f_t, "u(t-$c) ($A*(t-$c) + $B) e^($a*(t-$c))")->reduce;
} else { # Type III partial fractions
$b = abs($b);
$num = Formula($F_s, "$A s + ($B*$b - $A*$a)")->reduce;
$den = Formula($F_s, "s^2 - (2*$a)s + ($b*$b+$a*$a)")->reduce;
$yt = Formula($f_t, "u(t-$c) ($A cos($b(t-$c)) + $B sin($b(t-$c))) e^($a*(t-$c))")->reduce;
}
$Ys = $num/$den; $Ys = Formula($F_s, "$Ys e^(-$c s)");
###################################################
##
## Problem Text
Context()->texStrings;
BEGIN_TEXT
Compute the inverse Laplace transform:
$PAR
\(\displaystyle \mathcal{L}^{\text{-}1}\,\biggl\lbrace $Ys \biggr\rbrace = \)
\{ ans_rule(40) \}
$PAR
$SPACE $SPACE (${BBOLD}Notation:${EBOLD} write ${BBOLD}u(t-c)${EBOLD} for the Heaviside step
function \(u_c(t)\) with step at \(t=c\).)
END_TEXT
###################################################
##
## Hint
$showHint = 2;
if ($type == 1) { # Hint for Type I problem
$PF = "I";
$den_fact = Formula($F_pf, "(s - $a)*(s - $b)")->reduce;
$Ys_fact = $num/$den_fact;
$Ys_pf = Formula($F_pf, "A/(s-$a) + B/(s-$b)")->reduce;
$SPECIFIC_HINT =
"You must solve the ${BBOLD}Type I${EBOLD} partial fractions problem:${PAR}" .
"\(\displaystyle \qquad $Ys_fact = $Ys_pf\)";
} elsif ($type == 2) { # Hint for Type II problem
$PF = "II";
$den_fact = Formula($F_pf, "(s - $a)^2")->reduce;
$den_term = Formula($F_pf, "s-$a")->reduce;
$den_exp = Formula($f_t, "e^($a t)")->reduce;
$Ys_fact = $num/$den_fact;
$Ys_shift1 = Formula($F_pf, "($B (s+$a) + ($A-$B*$a))/s^2")->reduce;
$Ys_shift2 = Formula($F_pf, "($B s + $A)/s^2")->reduce;
$Ys_pf1 = Formula($F_pf,"A/(s-$a)^2 + B/(s-$a)")->reduce;
$Ys_pf2 = Formula($F_pf,"A/s^2 + B/s");
$SPECIFIC_HINT =
"There are two possible ways to solve:$PAR" .
"${BBOLD}(A)$EBOLD Solve the ${BBOLD}Type II$EBOLD partial fractions problem:$PAR " .
"\(\displaystyle \qquad $Ys_fact = $Ys_pf1\) " .
"${PAR}OR${PAR}" .
"${BBOLD}(B)$EBOLD Pull out the \($den_term\) as \($den_exp\), which changes$PAR " .
"\(\displaystyle \qquad $Ys_fact\ \) to be \(\displaystyle \ $Ys_shift1 = $Ys_shift2\)$PAR " .
"$SPACE $SPACE " .
"Then solve the ${BBOLD}very easy${EBOLD} Type II partial fractions problem:$PAR " .
"\(\displaystyle \qquad $Ys_shift2 = $Ys_pf2\)";
} else { # Hint for type III problem
$PF = "III";
$den_term = Formula($F_pf, "s-$a")->reduce;
$den_fact = Formula($F_pf, "($den_term)^2 + $b^2")->reduce;
$den_exp = Formula($f_t, "e^($a t)")->reduce;
$Ys_fact = $num/$den_fact;
$Ys_shift1 = Formula($F_pf, "($A (s+$a) + ($B*$b - $A*$a))/(s^2 + $b^2)")->reduce;
$Ys_shift2 = Formula($F_pf, "($A s + $B*$b)/(s^2 + $b^2)")->reduce;
$SPECIFIC_HINT =
"Pull out the \($den_term\) as \($den_exp\), which changes$PAR " .
"\(\displaystyle \qquad $Ys_fact \ \) to be \(\displaystyle \ $Ys_shift1 = $Ys_shift2\)";
}
BEGIN_TEXT
$BR $HR $PAR
If you don't get this in $showHint tries, you can get a hint.
END_TEXT
BEGIN_HINT
$PAR $HR $PAR
\(\bullet\ \ \)
The denominator factors as: \($den = $den_fact\).
$PAR
\(\bullet\ \ \)
$SPECIFIC_HINT
END_HINT
Context()->normalStrings;
###################################################
##
## Check answer
ANS( $yt->cmp() );
COMMENT("Inverse Laplace with step and exponential. Randomly chooses Type I, II, III problem. Includes detailed Hint.");
ENDDOCUMENT();