-
-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathimpulse-response.pg
More file actions
151 lines (114 loc) · 3.62 KB
/
impulse-response.pg
File metadata and controls
151 lines (114 loc) · 3.62 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
## DESCRIPTION
## Systems of ODEs: Nonhomogeneous Systems
## ENDDESCRIPTION
## DBsubject(Differential equations)
## DBchapter(Higher order differential equations)
## DBsection(Variation of parameters)
## Date(24/11/2015)
## Institution(METU-NCC)
## Author(Benjamin Walter)
##################################
# Initialization
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGmatrixmacros.pl",
"parserMultiAnswer.pl",
"answerHints.pl",
);
#####################################
# Setup
Context("Numeric");
Context()->variables->{namePattern} = qr/[a-z][a-z0-9_]*'*/i;
Context()->variables->are(
t=>"Real",
r=>"Real",
y=>"Real", "y'"=>"Real", "y''"=>"Real",
);
Context()->flags->set(
zeroLevel=>0.001,
limits=>[0,2],
zeroLevelTol=>0.001
);
############################
# setup differential equation
my $a = random(-5,5,1); my $b;
do { $b = random(-5,5,1); } until ($a != $b); # roots of char. eqn.
$char_eqn = Formula("r^2 - ($a+$b) r + ($a*$b) ")->reduce;
$L = Formula("y'' - ($a+$b) y' + ($a*$b) y")->reduce; # DE
my $c = non_zero_random(-9,9,1);
$g = Formula("$c*t^2*e^{$a*t}")->reduce; # forcing function
my $c1 = non_zero_random(-3,3,1); my $c2;
if ($b != 0) {
$c2 = random(max(int ((-9-$a*$c1)/$b),-10), min(int ((9-$a*$c1)/$b),10), 1);
} else {
$c2 = random(int (-9/abs($a)), int (9/abs($a)), 1);
}
$y0 = $c1 + $c2;
$dy0 = $a*$c1 + $b*$c2;
#############################
# answer evaluators
# A -- homogeneous, initial values
$IVP = Formula("$c1*e^($a*t) + $c2*e^($b*t)")->reduce;
# B -- homogeneous, impulse response
$IR = Formula("(e^($a*t) - e^($b*t))/($a-$b)")->reduce;
# C -- forcing function
# Main text
Context()->texStrings;
BEGIN_TEXT
Solutions to linear differential equations can be written using convolutions
as
\[ y \ \ = \ \ y_{\mathrm{IVP}} \ \ + \ \ \Bigl(h(t) \ {\Large \ast} \ f(t)\Bigr) \]
\( \qquad \bullet\)
\( y_{\mathrm{IVP}} \) is the solution to the
associated homogeneous differential equation with the given initial values
$BR \(\qquad\qquad\) (ignore the forcing function, keep initial values).
$BR
\( \qquad \bullet\)
\( h(t) \) is the ${BTT}impulse response${ETT}
$BR \(\qquad\qquad\) (ignore the initial values and forcing function).
$BR
\( \qquad \bullet\)
\( f(t) \) is the forcing function.
$BR \(\qquad\qquad\) (ignore the initial values and differential equation).
$PAR
$HR
$PAR
Use the form above to write the solution to the differential equation
\[ $L = $g \qquad \mathrm{with} \quad y(0) = $y0, \quad y'(0) = $dy0 \]
$PAR
\( y \ \ = \ \ \)\{ans_rule(10)\}\( \quad + \quad
\Bigl(\)\{ans_rule(10)\}\(\!\Large\ast\)\{ans_rule(10)\}\(\Bigr)\)
END_TEXT
$showHint = 1;
BEGIN_TEXT
$BR
$HR
$PAR
If you don't get this in $showHint tries, you can get a hint.
END_TEXT
BEGIN_HINT
You can quickly compute the impulse response by converting the impulse at \(t=0\)
to an initial velocity. Solve
\[ $L = 0,\qquad \mathrm{with}\quad y(0) = 0, \quad y'(0) = 1\]
using the characteristic equation
\[ $char_eqn = 0 \]
and plugging in to compute \(c_1\) and \(c_2\).
(You could also compute using Laplace transforms, but that is more slow.)
$PAR
$HR
$PAR
To be accepted, your answer must be entered into webwork as $BR
$SPACE $SPACE ${BTT}(Impulse resp.)${ETT}\(\Large\ast\)${BTT}(Forcing fun.)${ETT} $BR
${BITALIC}Hint:${EITALIC} The forcing function is \(f(t) = $g\).
END_HINT
Context()->normalStrings;
#####################################
# Answer evaluation
$showPartialCorrectAnswers = 2;
ANS( $IVP->cmp() );
ANS( $IR->cmp() );
ANS( $g->cmp() );
COMMENT('MathObject version. Randomized -- DISTINCT roots.');
ENDDOCUMENT();