#!/usr/bin/env python # coding: utf-8 # # Homework 9 # ### Problem 1 # # Write a function called "uc" that will convert units ("uc" for "unit conversion", "uc" because its short, and easy to type). The function should take a string argument. The value this string holds will determine a multiplication factor to return, which does the unit conversion. # # For example, If I have a variable ```x``` in units of feet, and I want to convert it to meters, I might have something like: # # ``` x * uc("ft_to_m") ``` # # where uc is the function, and "ft_to_m" is a string I pass to the function. The function has to decide what kind of unit conversion based on the string it is passed. # # Set up the function to allow conversions from the following: # * ft to m # * s to hr # * lbm to kg # * J to Btu # # and vice-versa for each. # # The function should include a docstring documentation. # # **Don't use pint for this** # In[ ]: # ### Problem 2 # You are given the following function: # # $$ y(t) = 5\left[1-\exp\left(-\frac{(t-\theta)}{\tau}\right)\right]S(t),$$ # # $$ S(t) = \left\{\begin{align} 0 & \mbox{ when }t<\theta \\ 1 & \mbox{ when }t\ge\theta\end{align}.\right.$$ # # Write a function called ```y``` for $y(t)$ according to this equation. Pass in $\theta$ and $\tau$ as extra parameters that have default values of 0.1 and 0.2, respectively. Evaluate the function at t=0.1 using the default values of $\tau$ and $\theta$, and with values $\tau = 0.05$ and $\theta = 0.1$. # In[ ]: # ### Problem 3 # # The Redlich-Kwong (RK) equation is more accurate than the Ideal Gas Law because it allows for molecular interactions at high pressures. The RK equation of state and the ideal gas law, are, respectively: # $$P_{RK} = \frac{RT}{V-b}-\frac{a}{V(V+b)\sqrt{T}}$$ # $$P_{IG} = \frac{RT}{V}$$ # Here, $V$ is molar volume. Also, # $$a = 0.427 R^2T_c^{2.5}/P_c,$$ # $$b = 0.0866 RT_c/P_c,$$ # $$R = 0.0821\,\,\mbox{liter-atm/(mol*K)}.$$ # # Code up these equations. Make sure to document your code by including units and variable descriptions. Evaluate $P_{RK}$, and $P_{IG}$ for air for $T=500$ K, $V=0.18$ ft$^3$/mol, $P_c=37.7$ bar, and $T_c=132.5$ K. Report the pressures in units of Pa. # # **Use the pint package to handle units.** # In[ ]: