Difference between revisions of "Modelling and scientific computing"

From Process Model Formulation and Solution: 3E4
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'''
'''Calculating relative error'''
<syntaxhighlight lang="python">
<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)))
</syntaxhighlight>
    </code>
</div></html>




'''working with integers'''
'''Working with integers'''
<syntaxhighlight lang="python">
<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)
</syntaxhighlight>
    </code>
</div></html>


'''working with floats'''
'''Working with floats'''
<syntaxhighlight lang="python">
<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)  
</syntaxhighlight>
    </code>
</div></html>


 
'''Special numbers'''
'''special numbers'''
<html><div data-datacamp-exercise data-lang="python" data-height="auto">
<syntaxhighlight lang="python">
    <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))   
</syntaxhighlight>
    </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)

Calculating relative error


Working with integers

Working with floats

Special numbers

Practice questions

  1. 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?
  2. Homework problem, similar to the case presented on slide 18, except
    • Use two inlet streams F1 and F2, and assume they are volumetric flow rates
    • An irreversible reaction occurs, A+3Br2C
    • The reaction rate for A = rA=kCACB3
    1. Derive the time-varying component mass balance for species B.
      • VdCBdt=F1inCB,1in+F2inCB,2inFoutCB+03kCACB3V
    2. What is the steady state value of CB? Can it be calculated without knowing the steady state value of CA?
      • F1inCB,1in+F2inCB,2inFoutCB3kCACB3V - we require the steady state value of CA, denoted as CA, to calculate CB.

More exercises available here