Difference between revisions of "EGR 103/Fall 2019/Minilab 3"
Jump to navigation
Jump to search
(→References / Hints) |
|||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | == Typographical Errors == | ||
+ | * 3.5.4 originally had part of the transfer function wrong; it should be: | ||
+ | :$$H=\frac{(j\omega)(j\omega+2000)}{(j\omega+10)(j\omega+1000)}$$ | ||
+ | |||
== References / Hints == | == References / Hints == | ||
− | * Problem | + | * Problem 3.5.1 |
** To load data from an Excel file with headers: | ** To load data from an Excel file with headers: | ||
::<syntaxhighlight lang=python> | ::<syntaxhighlight lang=python> | ||
Line 15: | Line 19: | ||
:* [https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.interpolate.CubicSpline.html scipy.interpolate.CubicSpline¶] at [http://docs.scipy.org docs.scipy.org] | :* [https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.interpolate.CubicSpline.html scipy.interpolate.CubicSpline¶] at [http://docs.scipy.org docs.scipy.org] | ||
− | * Problem | + | * Problem 3.5.2 |
** [https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.simps.html scipy.integrate.simps] at [http://docs.scipy.org docs.scipy.org] | ** [https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.simps.html scipy.integrate.simps] at [http://docs.scipy.org docs.scipy.org] | ||
** Note that the denominator in the line of action calculation is $$f_t$$, which you already calculated. | ** Note that the denominator in the line of action calculation is $$f_t$$, which you already calculated. | ||
+ | ** The equation for the line of action, $$d$$, is on the second page of the problem. | ||
+ | ** $$D$$ is the total depth of the water (75) | ||
** If you want to see a graph of the cross section (i.e. Figure 19.9(b)), assuming you call the height above the bottom $$z$$ and the width at that height $$wz$$, you can add the following code: | ** If you want to see a graph of the cross section (i.e. Figure 19.9(b)), assuming you call the height above the bottom $$z$$ and the width at that height $$wz$$, you can add the following code: | ||
::<syntaxhighlight lang=python> | ::<syntaxhighlight lang=python> | ||
Line 28: | Line 34: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | * Problem | + | * Problem 3.5.3 |
+ | ** [https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.quad.html scipy.integrate.quad] at [http://docs.scipy.org docs.scipy.org] | ||
+ | *** Be careful! Look at how many results the quad function gives back - you don't need all of them! | ||
** [https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.trapz.html scipy.integrate.trapz] at [http://docs.scipy.org docs.scipy.org] | ** [https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.trapz.html scipy.integrate.trapz] at [http://docs.scipy.org docs.scipy.org] | ||
** [https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.simps.html scipy.integrate.simps] at [http://docs.scipy.org docs.scipy.org] | ** [https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.simps.html scipy.integrate.simps] at [http://docs.scipy.org docs.scipy.org] | ||
− | ** Since $$n$$ goes from 2 to | + | ** Since $$n$$ goes from 2 to 100, it is not '''exactly''' what you need for an index to an array to save the integral estimates...think carefully about how to store things. |
+ | ** For the plots with the various integrals, the independent axis will be your $$n$$ values (i.e. range(2, 101)) | ||
− | * Problem | + | * Problem 3.5.4 |
** [https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.semilogx.html matplotlib.pyplot.semilogx] at [https://matplotlib.org matplotlib.org] | ** [https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.semilogx.html matplotlib.pyplot.semilogx] at [https://matplotlib.org matplotlib.org] | ||
** [[Python:Extrema]] | ** [[Python:Extrema]] | ||
** [[Python:Finding roots]] | ** [[Python:Finding roots]] | ||
+ | ** Note that the arguments to the np.logspace() command are the *powers* of 10 and the number of points; that is, to go from 100 to 1000 with 40 points, you would use <code>np.logspace(2, 4, 40)</code> | ||
+ | ** When you are looking for the maximum value and the cutoff frequencies, note that you are always looking at the absolute value of the transfer function; you can use <code>abs()</code> or <code>np.abs()</code> for that. | ||
+ | ** There are four main ways to make plots in terms of the scaling of the axes: | ||
+ | *** <code>ax.plot(x, y)</code> uses linear scaling on both axes | ||
+ | *** <code>ax.semilogx(x, y)</code> uses logarithmic scaling on the $$x$$ axis only | ||
+ | *** <code>ax.semilogy(x, y)</code> uses logarithmic scaling on the $$y$$ axis only | ||
+ | *** <code>ax.loglog(x, y)</code> uses logarithmic scaling on both axes | ||
== Partial Solutions == | == Partial Solutions == | ||
− | * Problem | + | * Problem 3.5.1 |
** Biggest difference happens at about $$x=30$$. | ** Biggest difference happens at about $$x=30$$. | ||
** Estimates of $$f(50)$$ are 0.471 and 0.521 for natural and not-a-knot, respectively. | ** Estimates of $$f(50)$$ are 0.471 and 0.521 for natural and not-a-knot, respectively. | ||
− | * Problem | + | * Problem 3.5.2 |
− | ** Total force is about 4e9; | + | ** Total force is about 4e9; the line of action $$d$$ is in the high 20s. |
− | * Problem | + | * Problem 3.5.3 |
** Exact answer is 1104. | ** Exact answer is 1104. | ||
** Simps is always better than trapz except for $$n=2$$, where they are the same. | ** Simps is always better than trapz except for $$n=2$$, where they are the same. | ||
** After about $$n=1$$ the true percent error goes to almost 0 based on scale of the graph. | ** After about $$n=1$$ the true percent error goes to almost 0 based on scale of the graph. | ||
− | * Problem | + | * Problem 3.5.4 |
** The plot looks like someone started drawing a duck from the back of the neck over the head and out to the end of the bill, then stopped. | ** The plot looks like someone started drawing a duck from the back of the neck over the head and out to the end of the bill, then stopped. | ||
** The maximum value on the graph is about 6. | ** The maximum value on the graph is about 6. | ||
** The maximum value of the absolute value of the transfer function is about 2. Note that $$20\log_{10}(2)=6.02$$, which explains why the max of the graph is where it is. | ** The maximum value of the absolute value of the transfer function is about 2. Note that $$20\log_{10}(2)=6.02$$, which explains why the max of the graph is where it is. | ||
** The cutoff frequencies are at approximately 10 and 1450. | ** The cutoff frequencies are at approximately 10 and 1450. |
Latest revision as of 22:14, 3 December 2019
Typographical Errors
- 3.5.4 originally had part of the transfer function wrong; it should be:
- $$H=\frac{(j\omega)(j\omega+2000)}{(j\omega+10)(j\omega+1000)}$$
References / Hints
- Problem 3.5.1
- To load data from an Excel file with headers:
import pandas # %% Load data edata = pandas.read_excel("file.xlsx") col_1_stuff = edata.values[:, 0].copy() col_2_stuff = edata.values[:, 1].copy()
- Problem 3.5.2
- scipy.integrate.simps at docs.scipy.org
- Note that the denominator in the line of action calculation is $$f_t$$, which you already calculated.
- The equation for the line of action, $$d$$, is on the second page of the problem.
- $$D$$ is the total depth of the water (75)
- If you want to see a graph of the cross section (i.e. Figure 19.9(b)), assuming you call the height above the bottom $$z$$ and the width at that height $$wz$$, you can add the following code:
fig = plt.figure(num=1, clear=True) ax = fig.add_subplot(1, 1, 1) zval = np.block([z[::-1], z[:]]) wval = np.block([-wz[::-1] / 2, wz[:] / 2]) ax.plot(wval, zval, "k-") ax.axis("equal")
- Problem 3.5.3
- scipy.integrate.quad at docs.scipy.org
- Be careful! Look at how many results the quad function gives back - you don't need all of them!
- scipy.integrate.trapz at docs.scipy.org
- scipy.integrate.simps at docs.scipy.org
- Since $$n$$ goes from 2 to 100, it is not exactly what you need for an index to an array to save the integral estimates...think carefully about how to store things.
- For the plots with the various integrals, the independent axis will be your $$n$$ values (i.e. range(2, 101))
- scipy.integrate.quad at docs.scipy.org
- Problem 3.5.4
- matplotlib.pyplot.semilogx at matplotlib.org
- Python:Extrema
- Python:Finding roots
- Note that the arguments to the np.logspace() command are the *powers* of 10 and the number of points; that is, to go from 100 to 1000 with 40 points, you would use
np.logspace(2, 4, 40)
- When you are looking for the maximum value and the cutoff frequencies, note that you are always looking at the absolute value of the transfer function; you can use
abs()
ornp.abs()
for that. - There are four main ways to make plots in terms of the scaling of the axes:
ax.plot(x, y)
uses linear scaling on both axesax.semilogx(x, y)
uses logarithmic scaling on the $$x$$ axis onlyax.semilogy(x, y)
uses logarithmic scaling on the $$y$$ axis onlyax.loglog(x, y)
uses logarithmic scaling on both axes
Partial Solutions
- Problem 3.5.1
- Biggest difference happens at about $$x=30$$.
- Estimates of $$f(50)$$ are 0.471 and 0.521 for natural and not-a-knot, respectively.
- Problem 3.5.2
- Total force is about 4e9; the line of action $$d$$ is in the high 20s.
- Problem 3.5.3
- Exact answer is 1104.
- Simps is always better than trapz except for $$n=2$$, where they are the same.
- After about $$n=1$$ the true percent error goes to almost 0 based on scale of the graph.
- Problem 3.5.4
- The plot looks like someone started drawing a duck from the back of the neck over the head and out to the end of the bill, then stopped.
- The maximum value on the graph is about 6.
- The maximum value of the absolute value of the transfer function is about 2. Note that $$20\log_{10}(2)=6.02$$, which explains why the max of the graph is where it is.
- The cutoff frequencies are at approximately 10 and 1450.