Difference between revisions of "Modelling and scientific computing"
Jump to navigation
Jump to search
Line 12: | Line 12: | ||
* Python code used in class for ... | * Python code used in class for ... | ||
''' | '''Calculating relative error''' | ||
< | <html><div data-datacamp-exercise data-lang="python" data-height="auto"> | ||
<code data-type="sample-code"> | |||
import numpy as np | import numpy as np | ||
y = 13.0 | y = 13.0 | ||
Line 29: | Line 30: | ||
print('Used %d iterations to calculate sqrt(%f) = %.20f; ' | print('Used %d iterations to calculate sqrt(%f) = %.20f; ' | ||
'true value = %.20f\n ' % (iter, y, x, np.sqrt(y))) | 'true value = %.20f\n ' % (iter, y, x, np.sqrt(y))) | ||
</ | </code> | ||
</div></html> | |||
''' | '''Working with integers''' | ||
< | <html><div data-datacamp-exercise data-lang="python" data-height="auto"> | ||
<code data-type="sample-code"> | |||
import numpy as np | import numpy as np | ||
Line 45: | Line 48: | ||
# Smallest and largest 32-bit integer | # Smallest and largest 32-bit integer | ||
print(np.iinfo(np.int32).min, np.iinfo(np.int32).max) | print(np.iinfo(np.int32).min, np.iinfo(np.int32).max) | ||
</ | </code> | ||
</div></html> | |||
''' | '''Working with floats''' | ||
< | <html><div data-datacamp-exercise data-lang="python" data-height="auto"> | ||
<code data-type="sample-code"> | |||
import numpy as np | import numpy as np | ||
Line 65: | Line 70: | ||
# of float is precise. | # of float is precise. | ||
print('decimal precision = %.10g' % np.finfo(f).precision) | print('decimal precision = %.10g' % np.finfo(f).precision) | ||
</ | </code> | ||
</div></html> | |||
'''Special numbers''' | |||
''' | <html><div data-datacamp-exercise data-lang="python" data-height="auto"> | ||
< | <code data-type="sample-code"> | ||
import numpy as np | import numpy as np | ||
Line 100: | Line 106: | ||
# The print out here should "True", but it prints "False" | # The print out here should "True", but it prints "False" | ||
print((1.0 + (e + e)) == (1.0 + e + e)) | print((1.0 + (e + e)) == (1.0 + e + e)) | ||
</ | </code> | ||
</div></html> | |||
==Practice questions== | ==Practice questions== |
Revision as of 21:29, 14 January 2019
Process modelling slides
Please download the lecture slides. 13 September 2010 (slides 1 to 8)
15 September 2010 (slides 9 to 15)
16 September 2010 (slides 16 to 19)
20 September 2010 (slides 20 to the end)
Approximation and computer representation
Please download the lecture slides. 22 and 23 September (updated)
- More about the Ariane 5 rocket 16-bit overflow
- Python code used in class for ...
Calculating relative error
Working with integers
Working with floats
Special numbers
Practice questions
- From the Hangos and Cameron reference, (available here] - accessible from McMaster computers only)
- Work through example 2.4.1 on page 33
- Exercise A 2.1 and A 2.2 on page 37
- Exercise A 2.4: which controlling mechanisms would you consider?
- Homework problem, similar to the case presented on slide 18, except
- Use two inlet streams
and , and assume they are volumetric flow rates - An irreversible reaction occurs,
- The reaction rate for A =
- Derive the time-varying component mass balance for species B.
- What is the steady state value of
? Can it be calculated without knowing the steady state value of ? - we require the steady state value of , denoted as , to calculate .
- Use two inlet streams