Created
November 6, 2012 15:41
-
-
Save tsbertalan/4025516 to your computer and use it in GitHub Desktop.
CBE 502 HW4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import exp, cos, sin | |
def print_answers(fs, fnames, W, tx=4.0): | |
for (name, f) in zip(fnames, fs): | |
print name+'(', tx, '):', f(tx) | |
print " W(", tx, "):", W(tx) | |
def n32b(): | |
f1 = lambda t: exp(float(t)) * (3.0 / 4.0 - t / 2) - exp(-1.0 * t) / 4 | |
f1p = lambda t: exp(float(t))*(1./4-t/2)+exp(-t)/4 | |
f1pp = lambda t: -(1./4+t/2.)*exp(float(t)) - exp(-1.*t)/4. | |
f2 = lambda t: exp(float(t)) / 2.0 - exp(-1.0 * t) / 2 | |
f2p = lambda t: exp(float(t))/2 + exp(-float(t))/2. | |
f2pp = lambda t: exp(float(t))/2 - exp(-float(t))/2. | |
f3 = lambda t: exp(float(t)) * (t / 2.0 - 0.25) + exp(-1.0 * t) / 4 | |
f3p = lambda t: exp(float(t))*(t/2.+1/4.) - exp(-float(t))/4. | |
f3pp = lambda t: exp(float(t))*(t/2. + .75) + exp(-float(t))/4. | |
def W(t): | |
t = float(t) | |
return f1(t)*f2p(t)*f3pp(t) + f2(t)*f3p(t)*f1pp(t) + f3(t)*f1p(t)*f2pp(t) \ | |
-f3(t)*f2p(t)*f1pp(t) - f2(t)*f1p(t)*f3pp(t) - f1(t)*f3p(t)*f2pp(t) | |
return [[f1, f2, f3], W] | |
[[f1, f2, f3], W] = n32b() | |
print "3.2 (b)" | |
print_answers([f1, f2, f3], ['f1', 'f2', 'f3'], W) | |
def n32e(): | |
def f1(t): | |
t = float(t) | |
return exp(-t)*cos(t) + exp(-t)*sin(t) | |
def f1p(t): | |
t = float(t) | |
return 0 | |
def f2(t): | |
t = float(t) | |
return exp(-t)*sin(t) | |
def f2p(t): | |
t = float(t) | |
return exp(-t)*cos(t) - exp(-t)*sin(t) | |
def W(t): | |
return f1(t)*f2p(t) - f2(t)*f1p(t) | |
return [[f1, f2], W] | |
print "" | |
print "3.2 (b)" | |
[[f1, f2], W] = n32e() | |
print_answers([f1, f2], ['f1', 'f2'], W) | |
print "" | |
print "3.3" | |
[[f1, f2, f3], W] = n32b() | |
print_answers([f1, f2], ['f1', 'f2'], W, tx=0.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment