Difference between revisions of "Modelling and scientific computing"

From Process Model Formulation and Solution: 3E4
Jump to navigation Jump to search
Line 18: Line 18:
</pdfreflow>
</pdfreflow>


 
* More about [http://www.around.com/ariane.html the Ariane 5 rocket] 16-bit overflow
Python code used in class for ...
* Python code used in class for ...
{| class="wikitable"
{| class="wikitable"
|-
|-

Revision as of 02:30, 23 September 2010

Process modelling slides

<pdfreflow> class_date = 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) button_label = Create my course notes! show_page_layout = 1 show_frame_option = 1 pdf_file = A-Modelling-20-Sept-2010.pdf </pdfreflow>

Approximation and computer representation

<pdfreflow> class_date = 22 and 23 September button_label = Create my course notes! show_page_layout = 1 show_frame_option = 1 pdf_file = A-Approximation-and-roundoff-22-Sept-2010.pdf </pdfreflow>

calculating relative error working with integers
import numpy as np
y = 13.0
n = 3                           # number of significant figures
rel_error = 0.5 * 10 ** (2-n)   # relative error calculation
x = y / 2.0
x_prev = 0.0
iter = 0
while abs(x - x_prev)/x > rel_error:
    x_prev = x
    x = (x + y/x) / 2.0
    print(abs(x - x_prev)/x)
    iter += 1
    
print('Used %d iterations to calculate sqrt(%f) = %.20f; '
      'true value = %.20f\n ' % (iter, y, x, np.sqrt(y)))
import numpy as np

print(np.int16(32767))
print(np.int16(32767+1))
print(np.int16(32767+2))

# Smallest and largest 16-bit integer
print(np.iinfo(np.int16).min, np.iinfo(np.int16).max)

# Smallest and largest 32-bit integer
print(np.iinfo(np.int32).min, np.iinfo(np.int32).max)

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 \(\sf F_1\) and \(\sf F_2\), and assume they are volumetric flow rates
    • An irreversible reaction occurs, \(\sf A + 3B \stackrel{r}{\rightarrow} 2C\)
    • The reaction rate for A = \(\sf -r_A = -kC_\text{A} C_\text{B}^3\)
    1. Derive the time-varying component mass balance for species B.
      • \( V\frac{dC_B}{dt} = F^{\rm in}_1 C^{\rm in}_{\sf B,1} + F^{\rm in}_2 C^{\rm in}_{\sf B,2} - F^{\rm out} C_{\sf B} + 0 - 3 kC_{\sf A} C_{\sf B}^3 V \)
    2. What is the steady state value of \(\sf C_B\)? Can it be calculated without knowing the steady state value of \(\sf C_A\)?
      • \( F^{\rm in}_1 C^{\rm in}_{\sf B,1} + F^{\rm in}_2 C^{\rm in}_{\sf B,2} - F^{\rm out} \overline{C}_{\sf B} - 3 k \overline{C}_{\sf A} \overline{C}^3_{\sf B} V \) - we require the steady state value of \(C_{\sf A}\), denoted as \(\overline{C}_{\sf A}\), to calculate \(\overline{C}_{\sf B}\).

More exercises to come