Open Educational Resources

Python Lab Tutorials: Lab 1

  1. Write a function in Python whose inputs are another function f and two values a and b. If a<b, the output of the function should be the vector [a,b,f(a),f(b)], otherwise, the function should return the message: “Please ensure that a is less than b“. Show that this function works properly for different cases.
  2. Use a “for” loop to create a function whose input is a vector of numbers. The function should check for the first occurrence of a number whose absolute value is less than 0.0005. The function should output the index number and that particular value. For example, if the input is the vector v=[1,3,2,5,0.1,0.2,-0.0004,0.03,0.000005], then the output should be [6,-0.0004]. If none of the absolute values of the components of the vector is less than 0.0005, the function should output: “N/A”. Repeat the problem using a “while” loop.
  3. The von Mises stress \sigma_{vM} (or sometimes called equivalent stress) gives a positive measure of the state of stress given by the symmetric stress matrix:

        \[\sigma=\left(\begin{matrix}\sigma_{11} & \sigma_{12} & \sigma_{13} \\ \sigma_{12} & \sigma_{22} & \sigma_{23} \\ \sigma_{13} & \sigma_{23} & \sigma_{33} \end{matrix}\right)\]


    \sigma_{vM} is defined as:

        \[\sigma_{vM}=\sqrt{\frac{(\sigma_{11}-\sigma_{22})^2+(\sigma_{22}-\sigma_{33})^2+(\sigma_{11}-\sigma_{33})^2+6(\sigma_{12}^2+\sigma_{13}^2+\sigma_{23}^2)}{2}}\]


    Create a function in Python whose argument is a 3\times 3 matrix and whose output is the von Mises stress. Use this function to show that the equivalent stress is the same for the following stress matrices (units of MPa):

        \[\sigma_a=\left(\begin{matrix}2&2&0\\2&5&0\\0&0&-5\end{matrix}\right)\qquad \sigma_b=\left(\begin{matrix}1&0&0\\0&-5&0\\0&0&6\end{matrix}\right)\]

Video Tutorials

Introduction to Google Colab

Python Basics

Sympy

Leave a Reply

Your email address will not be published.