the original function <i>f</i>. This can be stated symbolically as {\displaystyle F’=f}; The process of solving for antiderivatives is called antidifferentiation (or indefinite integration) and its opposite operation is called <i>differentiation</i>, which is the process of finding a derivative (from <a href="https://en.wikipedia.org/wiki/Antiderivative">https://en.wikipedia.org/wiki/Antiderivative</a>).</p><p id="c6fc">The Problem: Calculate the indefinite integral of the function:</p><p id="311d"><i>f’(x) = 4x³+12x+7</i>;</p><div id="0fcc"><pre><span class="hljs-number">07</span>_Solution (python <span class="hljs-built_in">cell</span> <span class="hljs-built_in">code</span>)<span class="hljs-symbol">:</span></pre></div><div id="df6f"><pre><span class="hljs-attribute">from</span> sympy import *
<span class="hljs-attribute">x</span>,f=symbols(<span class="hljs-string">"x f"</span>)
<span class="hljs-attribute">init_printing</span>()
<span class="hljs-attribute">f</span>=<span class="hljs-number">4</span>x*<span class="hljs-number">3</span>+<span class="hljs-number">12</span>*x-<span class="hljs-number">7</span>
<span class="hljs-attribute">integrate</span>(f,x)</pre></div><div id="3dee"><pre><span class="hljs-attribute">x</span>⁴+<span class="hljs-number">6</span>X²-<span class="hljs-number">7</span></pre></div><figure id="0b89"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*28Ui-fI6sQbDcHdFNY1hgA.png"><figcaption>Fig 12. Calculating the indefinite integral of the function <i>f’(x) = 4x³+12x-7 which results in f(x)=<b>x⁴+6X²-7</b></i></figcaption></figure><p id="08a8"><b>08#PyEx </b>— Python — <b>Linear System</b>:</p><p id="313f">The Problem: Using python, solve the following linear system:</p><ul><li>5x+y+3z=76</li><li>-x+2y+5z=35</li><li>4x-5y+z=22</li></ul><p id="2004">Edited: April2021 (Python3 adaptation; )</p><div id="d5e6"><pre><span class="hljs-number">08</span>_Solution (python <span class="hljs-built_in">cell</span> <span class="hljs-built_in">code</span>)<span class="hljs-symbol">:</span></pre></div><div id="433c"><pre>import numpy as np
A = np<span class="hljs-selector-class">.array</span>(<span class="hljs-selector-attr">[[5, 1, 3]</span>, <span class="hljs-selector-attr">[-1, 2, 5]</span>, <span class="hljs-selector-attr">[4, -5, 1]</span>])
<span class="hljs-selector-tag">b</span> = np<span class="hljs-selector-class">.array</span>(<span class="hljs-selector-attr">[76, 35, 22]</span>)
x = np<span class="hljs-selector-class">.linalg</span><span class="hljs-selector-class">.solve</span>(A,b)
<span class="hljs-function"><span class="hljs-title">print</span><span class="hljs-params">(x)</span></span></pre></div><div id="bbcf"><pre><span class="hljs-string">[10. 5. 7.]</span></pre></div><figure id="8313"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*H_XPbwJ_HNPp3gbRbxHg6A.png"><figcaption>Fig 13. The results of the above linear system: <b>[10. 5. 7.]</b></figcaption></figure><p id="4c87"><b>09#PyEx </b>— Python — <b>break-even point (BEP) in Economics</b>:</p><figure id="3f08"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*X19rGlKvzI3nZJpxZCL05A.png"><figcaption>Fig 14. BEP</figcaption></figure><p id="7e60">The <b>break</b>-<b>even point</b> (BEP) in <b>economics</b>, business — and specifically cost accounting — is the <b>point</b> at which total cost and total revenue are equal, i.e. “<b>even</b>”. There is no net loss or gain, and one has “<b>broken even</b>”, though opportunity costs have been paid and capital has received the risk-adjusted, expected return. In short, all costs that must be paid are paid, and there is neither profit nor loss:/</p><p id="bc48">The Problem: A company that produces <b>honeycomb polycarbonate</b> has a production cost of 129 per unit. Knowing that the sale of the product is 193.57 and the monthly production cost is 18322.80, obtain, using python, the BEP (I’ll use <i>R</i> for total Revenue, <i>C</i> for total Cost, <i>x</i> for Units sold, <i>xp — </i>x-axis<i> — </i>for the number of products sold to reach BEP point and <i>yp — y-axis — </i>for BEP point in).</p><figure id="8bf7"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*D1lhVumMxb0GuikP.png"><figcaption>Fig 15. honeycomb polycarbonate sheet</figcaption></figure><div id="f7a3"><pre><span class="hljs-number">09</span>_Solution (python <span class="hljs-built_in">cell</span> <span class="hljs-built_in">code</span>)<span class="hljs-symbol">:</span></pre></div><div id="2210"><pre><span class="hljs-attribute">from</span> sympy import *
<span class="hljs-attribute">C</span>,R,x=symbols(<span class="hljs-string">"C R x"</span>)
<span class="hljs-attribute">init_printing</span>()
<span class="hljs-attribute">R</span>=<span class="hljs-number">193</span>.<span class="hljs-number">57</span>*x
<span class="hljs-attribute">C</span>=<span class="hljs-number">129</span>*x+<span class="hljs-number">18322</span>.<span class="hljs-number">80</span>
<span class="hljs-attribute">xp</span>=solve(Eq(R,C),x)
<span class="hljs-attribute">yp</span>=R.subs(x, xp[<span class="hljs-number">0</span>])
<span class="hljs-attribute">print</span>(xp[<span class="hljs-number">0</span>])
<span class="hljs-attribute">print</span>(yp)</pre></div><div id="8257"><pre><span class="hljs-attribute">283</span>.<span class="hljs-number">766455010067</span>
<span class="hljs-attribute">54928</span>.<span class="hljs-number">6726962986</span></pre></div><figure id="ee17"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*tdymSFp4ytusFiC6qtS8_Q.png"><figcaption>Fig 16. The results of the above the <b>break</b>-<b>even point</b> (BEP) equation is<b> 283.766455010067 </b>and<b> 54928.6726962986; </b>which means that<b> </b>the company has to sell <b>284</b> products and the revenue will be balanced when the total revenue is $ <b>54929</b>:)</figcaption></figure><p id="bd72"><b>10#PyEx </b>— Python — <a href="https://readmedium.com/linear-regressions-the-basics-1a633f351ec2"><b>Linear regression</b></a><b>: Linear regression </b>is a common Statistical Data Analysis technique. It is used to determine the extent to which there is a linear relationship between a dependent variable and one or more independent variables. The equation has the form Y= a + bX, where Y is the dependent variable (that’s the variable that goes on the Y-axis), X is the independent variable (i.e. it is plotted on the X-axis), b is the slope of the line and a is the y-intercept.</p><p id="7c3d">The Problem: The energy consumption in a residence is shown in table 2 below:</p>
<figure id="f33c">
<div>
<div>
<iframe class="gist-iframe" src="/gist/giljr/584306f07f7926c14b18b07f51babcfe.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="b5ea">Table 2 — energy consumption</p><p id="75be">The Problem: Obtain, via python, the regression line, the correlation coefficient, and plot the graph showing the line and the data:</p><div id="1b9c"><pre><span class="hljs-number">10</span>_Solution (python <span class="hljs-built_in">cell</span> <span class="hljs-built_in">code</span>)<span class="hljs-symbol">:</span></pre></div><div id="bf3b"><pre>import numpy as np
import matplotlib<span class="hljs-selector-class">.pyplot</span> as pyp
from scipy import stats
x=np<span class="hljs-selector-class">.array</span>(<span class="hljs-selector-attr">[1,2,3,4,5,6]</span>)
y=np<span class="hljs-selector-class">.array</span>(<span class="hljs-selector-attr">[134,126,141,145,139,142]</span>)
<span class="hljs-selector-tag">a</span>,<span class="hljs-selector-tag">b</span>,correlation,<span class="hljs-selector-tag">p</span>,error=stats<span class="hljs-selector-class">.linregress</span>(x,y)
<span class="hljs-function"><span class="hljs-title">print</span><span class="hljs-params">(<span class="hljs-string">'Regression line: y=%.2fx+%.2f'</span>% (a,b)</span></span>)
<span class="hljs-function"><span class="hljs-title">print</span><span class="hljs-params">(<span class="hljs-string">'Correlation Coefficient: r=%.2f'</span>% correlation)</span></span>
plt<span class="hljs-selector-class">.plot</span>(x,y,<span class="hljs-string">'o'</span>,label=<span class="hljs-string">'Original data'</span>)
f=a*x+<span class="hljs-selector-tag">b</span>
plt<span class="hljs-selector-class">.plot</span>(x,f,<span class="hljs-string">'r'</span>,label=<span class="hljs-string">'Regression Line'</span>)
plt<span class="hljs-selector-class">.ylim</span>(<span class="hljs-number">110</span>, <span class="hljs-number">160</span>)
plt<span class="hljs-selector-class">.legend</span>()
plt<span class="hljs-selector-class">.show</span>()</pre></div><div id="5085"><pre><span class="hljs-attribute">Regression</span> line: y=<span class="hljs-number">2</span>.<span class="hljs-number">37</span>x+<span class="hljs-number">129</span>.<span class="hljs-number">53</span>
<span class="hljs-attribute">Correlation</span> Coefficient: r=<span class="hljs-number">0</span>.<span class="hljs-number">65</span>
<span class="hljs-attribute">graphic</span> below</pre></div><figure id="da2a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*tufdgbtCxfW4SD7UXRDEtw.png"><figcaption>Fig 17. oops:/ Where is the scipy lib? There is no such a lib. <b>TO FIX IT</b>, type this at the console: <b>pip install scipy</b></figcaption></figure><figure id="2e88"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*Yoyy90hkfRqPkAtDsyKgbA.png"><figcaption>Fig 18. And there you have it! Congratulations!!! the equation that best represents the energy consumption of that residence is given by the line: f(x) = <b>2.37x+129.53; </b>with it, you can estimate what your monthly consumption will be and every month the system will adjust this equation, getting closer and closer to the most likely reality :)</figcaption></figure><p id="61eb"><b>11#PyEx </b>— Python — <b>Parabolic Function</b>: parabolic shape helps ensure that the <b>bridge</b> stays up and that the cables can sustain the weight of hundreds of cars and trucks each hour.</p><figure id="ac83"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*fYKcJhE7cEmeZtqF.jpg"><figcaption>Fig 19. San Francisco Bridge — The Golden Gate Bridge is a suspension bridge spanning the Golden Gate, the one-mile-wide (1.6 km) strait connecting San Francisco Bay and the Pacific Ocean</figcaption></figure><figure id="f8a2"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*jyU-tBjgerHUKBnZ"><figcaption>Fig 20. the banana has a parabola-shaped curvature, in case you didn’t know...</figcaption></figure><figure id="cbe4"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*qUxN7SqxYhQZ_qoI.jpg"><figcaption>Fig 21. Parabolas are also used in satellite dishes to help reflect signals that then go to a receiver. This specific satellite is the National Radio Astronomy Observatory, which operates the world premiere astronomical telescope operating from centimeter to millimeter wavelengths, and is located in Green Bank, West Virginia. Signals that go directly to the satellite will reflect off and back to the receiver after bouncing off the focus due to parabolas’ reflective properties.</figcaption></figure><p id="a989">The Problem: Obtain the parabola equation knowing that the points a (0,0), b (10,5), and c (20,0), in meters, belong to the structure of a bridge.</p><div id="a0db"><pre><span class="hljs-number">11</span>_Solution (python <span class="hljs-built_in">cell</span> <span class="hljs-built_in">code</span>)<span class="hljs-symbol">:</span></pre></div><div id="b354"><pre><span class="hljs-attribute">from</span> scipy.interpolate import *
<span class="hljs-attribute">x</span>=[<span class="hljs-number">0</span>,<span class="hljs-number">10</span>,<span class="hljs-number">20</span>]
<span class="hljs-attribute">y</span>=[<span class="hljs-number">0</span>,<span class="hljs-number">5</span>,<span class="hljs-number">0</span>]
<span class="hljs-attribute">f</span>=lagrange(x,y)
<span class="hljs-attribute">print</span>(f)</pre></div><div id="6780"><pre><span class="hljs-number">-0.05</span><span class="hljs-keyword">x</span>²+<span class="hljs-keyword">x</span></pre></div><figure id="9327"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*WDnR-sxAk3ZHe7P3erwheg.png"><figcaption>Fig 22. The bridge parabolic function is: f(x) =<b>-0.05x²+x; </b>can it be easier than that?</figcaption></figure><p id="5367"><b>12#PyEx </b>— Python — <b>Linear programming (LP)</b>: LP is a tool for solving optimization problems. In 194
Options
7, <a href="http://www.producao.ufrgs.br/arquivos/disciplinas/382_winston_cap3_introduction_to_linear_programming.pdf">George Dantzig </a>developed an efficient method, the simplex algorithm, for solving linear programming problems (also called LP). Since the development of the simplex algorithm, LP has been used to solve optimization problems in industries as diverse as banking, education, forestry, petroleum, and trucking. In a survey of Fortune 500 firms, 85% of the respondents said they had used linear programming, as a measure of the importance of linear programming in operations research:</p><p id="430b">Search for LP:</p><p id="42f9">(<a href="http://www.producao.ufrgs.br/arquivos/disciplinas/382_winston_cap3_introduction_to_linear_programming.pdf">Introduction to Linear Programming</a> from <a href="http://www.producao.ufrgs.br/arquivos/disciplinas/382_winston_cap3_introduction_to_linear_programming.pdf">ufrgs.br</a>).</p><p id="7992">or</p><p id="9595">(<a href="http://www.optimization-online.org/DB_FILE/2011/09/3178.pdf">http://www.optimization-online.org/DB_FILE/2011/09/3178.pdf</a>)</p><p id="a6de">The Problem: A Carrier Corporation has its deliveries optimized.</p><p id="e6dc">But on one day, one of his vehicles suffered an unusual attack:) was temporarily inoperative…</p><figure id="77ca"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*IKT2gdkiS-8UXQP7.png"><figcaption>Fig 23. Track unusual attack :/</figcaption></figure><p id="ba88">Now you need to formulate a Plan B for the delivery of two sets of important products A and B.</p><p id="170d">Each box of Product A weighs 20 kg and occupies 0.45m³.</p><p id="7265">Each box of Product B weighs 30 kg and occupies 0.35m³.</p><p id="2214">The profit for transporting Product A is 4.10.</p><p id="776f">The profit for transporting Product B is 5.40.</p><p id="c54d">The truck has the capacity to transport 2 tons and the space of 30m³.</p><p id="80e6">Knowing that the carrier wants to transport as many products as possible and obtain the highest possible profit, use linear programming, and solve the problem.</p><div id="598a"><pre><span class="hljs-number">12</span>_Solution (python <span class="hljs-built_in">cell</span> <span class="hljs-built_in">code</span>)<span class="hljs-symbol">:</span></pre></div><div id="8497"><pre><span class="hljs-keyword">import</span> sys
!{sys.executable} -m pip install pulp</pre></div><figure id="10c6"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*QP1uyefqyDcLeKjmIrx4tw.png"><figcaption>Fig 24. All the requirements are already satisfied \o/</figcaption></figure><div id="3fcf"><pre><span class="hljs-attribute">from</span> pulp import *
<span class="hljs-attribute">prob</span>=LpProblem('Example', LpMaximize)
<span class="hljs-attribute">x1</span>=LpVariable(<span class="hljs-string">"Product A"</span>, <span class="hljs-number">0</span>)
<span class="hljs-attribute">x2</span>=LpVariable(<span class="hljs-string">"Product B"</span>, <span class="hljs-number">0</span>)
<span class="hljs-attribute">prob</span> += <span class="hljs-number">4</span>.<span class="hljs-number">10</span>*x1 + <span class="hljs-number">5</span>.<span class="hljs-number">40</span>*x2
<span class="hljs-attribute">prob</span> += <span class="hljs-number">0</span>.<span class="hljs-number">45</span>*x1+<span class="hljs-number">0</span>.<span class="hljs-number">35</span>*x2 <= <span class="hljs-number">30</span>
<span class="hljs-attribute">prob</span> += <span class="hljs-number">20</span>*x1+<span class="hljs-number">30</span>*x2 <= <span class="hljs-number">2000</span>
<span class="hljs-attribute">prob</span>.solve()
<span class="hljs-attribute">for</span> v in prob.variables():
<span class="hljs-attribute">print</span>(v.name,<span class="hljs-string">"="</span>, v.varValue)
<span class="hljs-attribute">print</span>(<span class="hljs-string">"Max Profit = "</span>, value(prob.objective))</pre></div><div id="3628"><pre><span class="hljs-attribute">Product_A</span> = <span class="hljs-number">30</span>.<span class="hljs-number">769231</span>
<span class="hljs-attribute">Product_B</span> = <span class="hljs-number">46</span>.<span class="hljs-number">153846</span>
<span class="hljs-attribute">Max</span> Profit = <span class="hljs-number">375</span>.<span class="hljs-number">3846155</span></pre></div><figure id="a73b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*84-v6WmCOpNepXnbk9PmWw.png"><figcaption>Fig 25. And there you have it! Congratulations!!! The result is <b>Product_A = 30.769231 Product_B = 46.153846 Max Profit = 375.3846155</b>, which means that to achieve maximum profit, the carrier will have to load its truck with <b>30 boxes of Product A</b>, <b>46 boxes of Product B </b>and the <b>maximum profit of $ 375.38</b> will be reached!</figcaption></figure><p id="c425">And finally, that’s all!</p><p id="1617">I hope you can be as surprised just as I am surprised by the 💪Power of Python!</p><p id="6134">See you in the next PySeries!</p><p id="1540">Bye, for now, o/</p><p id="8bfb"><a href="https://github.com/giljr/py4engineer">Download all Files from the GitHub Repo</a></p><h2 id="02ec">References & Credits</h2><p id="f916">Thank you, Mr. <a href="https://www.facebook.com/people/Ricardo-A-Deckmann-Zanardini/100000334147770">Ricardo A. Deckmann Zanardini</a> — You are an Awesome Teacher! o/; Text edited while I’m studying Computer Engineer at <a href="https://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwiFtdj5lovrAhUNDJEKHcjtBxkYABAAGgJjZQ&ohost=www.google.com&cid=CAESQOD25BK94W2RIpTcjmQbZc6oBfGMExYDk0VsQhHV92UNtjm_uu5i-Atd66h20hYQcJMpJAkDIT75IlsYtYh4gww&sig=AOD64_2cC6J6H9kVwb_JXdIbzUuk9sLLDA&q&adurl&ved=2ahUKEwi__s75lovrAhX8GbkGHdy1DHgQ0Qx6BAgNEAE">Escola Superior Politécnica Uninter</a><a href="https://emojipedia.org/person-lifting-weights/">🏋</a>!</p><div id="cbcb" class="link-block">
<a href="https://code.visualstudio.com/">
<div>
<div>
<h2>Visual Studio Code — Code Editing. Redefined</h2>
<div><h3>Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud…</h3></div>
<div><p>code.visualstudio.com</p></div>
</div>
<div>
<div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*6635uBQzbOfK0bqt)"></div>
</div>
</div>
</a>
</div><p id="16a0">Visualizing quaternions (4d numbers) with stereographic projection — from <a href="https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw">3Blue1Brown</a></p><p id="a912"><a href="http://www.producao.ufrgs.br/arquivos/disciplinas/382_winston_cap3_introduction_to_linear_programming.pdf">Introduction to Linear Programming</a> from <a href="http://www.producao.ufrgs.br/arquivos/disciplinas/382_winston_cap3_introduction_to_linear_programming.pdf">ufrgs.br</a> (Universidade Federal do Rio Grande do Sul — Brazil)</p><p id="5ba7"><a href="http://www.optimization-online.org/DB_FILE/2011/09/3178.pdf">PuLP: A Linear Programming Toolkit for Python</a> by <a href="http://www.optimization-online.org/DB_FILE/2011/09/3178.pdf">optimization-online.org</a></p><h2 id="de1a">Posts Related:</h2><p id="6e31">00Episode#PySeries — Python — <a href="https://medium.com/@J.3/python-jupiter-notebook-quick-start-with-vscode-916c43c10d9a">Jupiter Notebook Quick Start with VSCode — How to Set your Win10 Environment to use Jupiter Notebook</a></p><p id="c969">01Episode#PySeries — Python — Python 4 Engineers — Exercises! An overview of the Opportunities Offered by Python in Engineering! (this one:)</p><p id="fdba">02Episode#<b>PySeries </b>— Python — <a href="https://readmedium.com/geogebra-plus-linear-programming-a51661c99590">Geogebra Plus Linear Programming- We’ll Create a Geogebra program to help us with our linear programming</a></p><p id="a2b9">03Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/python-4-engineers-more-exercises-5cbab729ef11">Python 4 Engineers — More Exercises! — Another Round to Make Sure that Python is Really Amazing!</a></p><p id="e4c4">04Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/linear-regressions-the-basics-1a633f351ec2">Linear Regressions — The Basics — How to Understand Linear Regression Once and For All!</a></p><p id="7082">05Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/numpy-init-python-review-f5362abbaaf9">NumPy Init & Python Review — A Crash Python Review & Initialization at NumPy lib.</a></p><p id="4acf">06Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/numpy-jupyter-notebook-1182f78ab4e1">NumPy Arrays & Jupyter Notebook — Arithmetic Operations, Indexing & Slicing, and Conditional Selection w/ np arrays</a>.</p><p id="4c9b">07Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/pandas-intro-series-970e206e2ad5">Pandas — Intro & Series — What it is? How to use it?</a></p><p id="d7a3">08Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/pandas-dataframes-7ba872dcbc30">Pandas DataFrames — The primary Pandas data structure! It is a dict-like container for Series objects</a></p><p id="ac80">09Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/python-4-engineers-even-more-exercises-d0141e0b06d">Python 4 Engineers — Even More Exercises! — More Practicing Coding Questions in Python!</a></p><p id="aff0">10Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/pandas-hierarchical-index-cross-section-30783023a274">Pandas — Hierarchical Index & Cross-section — Open your Colab notebook and here are the follow-up exercises!</a></p><p id="9179">11Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/pandas-missing-data-5142f3eda2b">Pandas — Missing Data — Let’s Continue the Python Exercises — Filling & Dropping Missing Data</a></p><p id="0026">12Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/pandas-group-by-3140d053b9c">Pandas — Group By — Grouping large amounts of data and compute operations on these groups</a></p><p id="e24c">13Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/pandas-merging-joining-concatenations-a35bbe1a9dd5">Pandas — Merging, Joining & Concatenations — Facilities For Easily Combining Together Series or DataFrame</a></p><p id="6f55">14Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/pandas-operations-4b8f7a4b4139">Pandas — Pandas Dataframe Examples: Column Operations</a></p><p id="278e">15Episode#<b>PySeries</b> — Python — <b>Python 4 Engineers </b>— Keeping It In The Short-Term Memory — <a href="https://readmedium.com/python-4-engineers-keeping-it-in-the-short-term-memory-4f9458016171"><b>Test Yourself!</b> Coding in Python, Again!</a></p><p id="7667">16Episode#<b>PySeries</b> — NumPy — <a href="https://readmedium.com/numpy-review-again-f94f1c1c77e8">NumPy Review, Again;)<b> </b></a>— Python Review Free Exercises</p><p id="7e13">17Episode#<b>PySeries</b> — <a href="https://readmedium.com/generators-in-python-8d3de173743e">Generators in Python<b></b></a><b><a href="https://readmedium.com/numpy-review-again-f94f1c1c77e8"><b> </b></a>— Python Review Free Hints</b></p><p id="bcee">18Episode#<b>PySeries</b> — P<a href="https://readmedium.com/panda-review-again-baf0687b35de">andas Review…Again;)</a> — Python Review Free Exercise</p><p id="baeb">19Episode#<b>PySeries</b> — <a href="https://readmedium.com/matlibplot-seaborn-python-libs-459f6666f35f">MatlibPlot & Seaborn Python Libs </a>— Reviewing theses Plotting & Statistics Packs</p><p id="f2ab">20Episode#<b>PySeries</b> — <a href="https://readmedium.com/seaborn-python-review-9e543b6b7a44">Seaborn Python Review</a> — Reviewing theses Plotting & Statistics Packs</p>
<figure id="9839">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLU_ZiWNUMYEW_cjmcaGm-w-JkqfQV4_1Z&display_name=YouTube&url=https%3A%2F%2Fwww.youtube.com%2Fplaylist%3Flist%3DPLU_ZiWNUMYEW_cjmcaGm-w-JkqfQV4_1Z&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYO0FrpkiG5k%2Fhqdefault.jpg%3Fsqp%3D-oaymwEWCKgBEF5IWvKriqkDCQgBFQAAiEIYAQ%3D%3D%26rs%3DAOn4CLCfjSxeHDGqAbxVK3qgkBgZzv9ZnQ&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=youtube" allowfullscreen="" frameborder="0" height="480" width="853">
</div>
</div>
</figure></iframe></div></div></figure></article></body>
Python 4 Engineers — Exercises!
An overview of the Opportunities Offered by Python in Engineering! — #PySeries#Episode 01
Hi, here are some exercises to start to see problems solutions issues things from another perspective: Python is a fantastic sci_tool! Check it out!
01#PyEx — Python — Mechanical Tolerance:
The Problem: A hole has a diameter of 80mm and a tolerance of -0.102 and +0.222. Determine the minimum and maximum dimensions of this hole using Python Jupiter Notebook:)
Fig 1. First problem illustration; If you have no Jupyter yet, please, considering following this tutorial :)
Fig 4. oops:/ The ModuleNotFoundError — Please, TOFIX IT, in console, type: pip install numpyFig 5. Run the cell again and there you have it! Solution: array([1.58217509+2.53665299j, 1.58217509–2.53665299j, 0.33564982+0.j ]); j is the imaginary part; note that in the third root we have only the real part; while studying quaternions to play in Unity, I understand what complex numbers are \o/ so please consider watching this video too: https://youtu.be/d4EgbgTm0Bg from 3Blue1Brown:)
04#PyEx — Python — Tables and Graphs: The following table 1 shows the number of downloads of an application from January to May of the year 2020.
table 1. App Downloads per Month
The Problem: Using python make a graph of lines with circles for each month related to the number of downloads with each of these months;
04_Solution (python cellcode):
import matplotlib.pyplot as plt
x=['Jan', 'Feb', 'Mar','Apr', 'May']
y=[127000, 133000, 129000, 134000, 136000]
plt.plot(x,y)
plt.plot(x,y,'r o')
plt.title("Downloads - From January to May")
plt.xlabel('Month')
plt.ylabel('Downloads')
plt. show()
graphic below
Fig 6. oops:/ there is no matplotlib installed; TO FIX IT, type this at console: pip install matplotlibFig 7. Run the cell again and there you have it! \o/
05#PyEx — Python — Pie charts:
The Problem: At McDonald’s international snack chain (the biggest fast-food company in the world), here in Brazil, has sold monthly online over 5226 BigMac, 2404 McSpicy, 3218 Cheeseburger, and 4321 McNuggets;
Fig 8. McDonald’s snacks menu \o/
Find Percentage of each product, and show results in a Pie Chart; highlighting the best selling snack of this month; use python, please:)
05_Solution (python cellcode):
import matplotlib.pyplot as plt
x=[5226,2404,3218,4321]
snacks=['BigMac','McSpicy','Cheeseburger','McNuggets']
colors=['r','m','y','g']
plt.axis('equal')
plt.pie(x,labels=snacks,colors=colors,shadow=True,explode=
(0.1,0,0,0),autopct=('%1.1f%%'))
plt.title('Snacks sold in a month')
plt.show()
graphic below
Fig 9. Running 05_Solution: McDonald’s pie o/
06#PyEx — Python — Derivatives: Derivatives can be used to calculate the profit and loss in business using graphs; to check the temperature variation; to determine the speed or distance covered such as miles per hour, kilometer per hour, to run Lego, Arduino, etc.
The Problem: Using python, calculate the first derivative of the function: f(x)=4x³+12x-7:
06_Solution (python cellcode):
from sympy import *
x,f=symbols("x f")
init_printing()
f=4*x**3+12*x-7diff(f,x)
12x²+12
Fig 10. oops:/ there is no such thing as sympy! TO FIX IT, type this at the console: pip install sympyFig 11. Run the cell again and there you go! f`(x)=12x²+12 is the first derivative of the function f(x)=4x³+12x-7:)
07#PyEx — Python: Indefinite Integral or Antiderivatives — In calculus, an antiderivative, inverse derivative, primitive function, primitive integral, or indefinite integral of a functionf is a differentiable functionF whose derivative is equal to the original function f. This can be stated symbolically as {\displaystyle F’=f}; The process of solving for antiderivatives is called antidifferentiation (or indefinite integration) and its opposite operation is called differentiation, which is the process of finding a derivative (from https://en.wikipedia.org/wiki/Antiderivative).
The Problem: Calculate the indefinite integral of the function:
f’(x) = 4x³+12x+7;
07_Solution (python cellcode):
from sympy import *
x,f=symbols("x f")
init_printing()
f=4*x**3+12*x-7integrate(f,x)
x⁴+6X²-7
Fig 12. Calculating the indefinite integral of the function f’(x) = 4x³+12x-7 which results in f(x)=x⁴+6X²-7
08#PyEx — Python — Linear System:
The Problem: Using python, solve the following linear system:
5x+y+3z=76
-x+2y+5z=35
4x-5y+z=22
Edited: April2021 (Python3 adaptation; )
08_Solution (python cellcode):
import numpy as np
A = np.array([[5, 1, 3], [-1, 2, 5], [4, -5, 1]])
b = np.array([76, 35, 22])
x = np.linalg.solve(A,b)
print(x)
[10. 5. 7.]
Fig 13. The results of the above linear system: [10. 5. 7.]
09#PyEx — Python — break-even point (BEP) in Economics:
Fig 14. BEP
The break-even point (BEP) in economics, business — and specifically cost accounting — is the point at which total cost and total revenue are equal, i.e. “even”. There is no net loss or gain, and one has “broken even”, though opportunity costs have been paid and capital has received the risk-adjusted, expected return. In short, all costs that must be paid are paid, and there is neither profit nor loss:/
The Problem: A company that produces honeycomb polycarbonate has a production cost of $ 129 per unit. Knowing that the sale of the product is $ 193.57 and the monthly production cost is $ 18322.80, obtain, using python, the BEP (I’ll use R for total Revenue, C for total Cost, x for Units sold, xp — x-axis — for the number of products sold to reach BEP point and yp — y-axis — for BEP point in $).
Fig 15. honeycomb polycarbonate sheet
09_Solution (python cellcode):
from sympy import *
C,R,x=symbols("C R x")
init_printing()
R=193.57*x
C=129*x+18322.80xp=solve(Eq(R,C),x)
yp=R.subs(x, xp[0])
print(xp[0])
print(yp)
283.76645501006754928.6726962986
Fig 16. The results of the above the break-even point (BEP) equation is 283.766455010067 and 54928.6726962986; which means thatthe company has to sell 284 products and the revenue will be balanced when the total revenue is $ 54929:)
10#PyEx — Python — Linear regression: Linear regression is a common Statistical Data Analysis technique. It is used to determine the extent to which there is a linear relationship between a dependent variable and one or more independent variables. The equation has the form Y= a + bX, where Y is the dependent variable (that’s the variable that goes on the Y-axis), X is the independent variable (i.e. it is plotted on the X-axis), b is the slope of the line and a is the y-intercept.
The Problem: The energy consumption in a residence is shown in table 2 below:
Table 2 — energy consumption
The Problem: Obtain, via python, the regression line, the correlation coefficient, and plot the graph showing the line and the data:
Fig 17. oops:/ Where is the scipy lib? There is no such a lib. TO FIX IT, type this at the console: pip install scipyFig 18. And there you have it! Congratulations!!! the equation that best represents the energy consumption of that residence is given by the line: f(x) = 2.37x+129.53; with it, you can estimate what your monthly consumption will be and every month the system will adjust this equation, getting closer and closer to the most likely reality :)
11#PyEx — Python — Parabolic Function: parabolic shape helps ensure that the bridge stays up and that the cables can sustain the weight of hundreds of cars and trucks each hour.
Fig 19. San Francisco Bridge — The Golden Gate Bridge is a suspension bridge spanning the Golden Gate, the one-mile-wide (1.6 km) strait connecting San Francisco Bay and the Pacific OceanFig 20. the banana has a parabola-shaped curvature, in case you didn’t know...Fig 21. Parabolas are also used in satellite dishes to help reflect signals that then go to a receiver. This specific satellite is the National Radio Astronomy Observatory, which operates the world premiere astronomical telescope operating from centimeter to millimeter wavelengths, and is located in Green Bank, West Virginia. Signals that go directly to the satellite will reflect off and back to the receiver after bouncing off the focus due to parabolas’ reflective properties.
The Problem: Obtain the parabola equation knowing that the points a (0,0), b (10,5), and c (20,0), in meters, belong to the structure of a bridge.
11_Solution (python cellcode):
from scipy.interpolate import *
x=[0,10,20]
y=[0,5,0]
f=lagrange(x,y)
print(f)
-0.05x²+x
Fig 22. The bridge parabolic function is: f(x) =-0.05x²+x; can it be easier than that?
12#PyEx — Python — Linear programming (LP): LP is a tool for solving optimization problems. In 1947, George Dantzig developed an efficient method, the simplex algorithm, for solving linear programming problems (also called LP). Since the development of the simplex algorithm, LP has been used to solve optimization problems in industries as diverse as banking, education, forestry, petroleum, and trucking. In a survey of Fortune 500 firms, 85% of the respondents said they had used linear programming, as a measure of the importance of linear programming in operations research:
The Problem: A Carrier Corporation has its deliveries optimized.
But on one day, one of his vehicles suffered an unusual attack:) was temporarily inoperative…
Fig 23. Track unusual attack :/
Now you need to formulate a Plan B for the delivery of two sets of important products A and B.
Each box of Product A weighs 20 kg and occupies 0.45m³.
Each box of Product B weighs 30 kg and occupies 0.35m³.
The profit for transporting Product A is $ 4.10.
The profit for transporting Product B is $ 5.40.
The truck has the capacity to transport 2 tons and the space of 30m³.
Knowing that the carrier wants to transport as many products as possible and obtain the highest possible profit, use linear programming, and solve the problem.
12_Solution (python cellcode):
import sys
!{sys.executable} -m pip install pulp
Fig 24. All the requirements are already satisfied \o/
from pulp import *
prob=LpProblem('Example', LpMaximize)
x1=LpVariable("Product A", 0)
x2=LpVariable("Product B", 0)
prob += 4.10*x1 + 5.40*x2
prob += 0.45*x1+0.35*x2 <= 30prob += 20*x1+30*x2 <= 2000prob.solve()
for v in prob.variables():
print(v.name,"=", v.varValue)
print("Max Profit = ", value(prob.objective))
Fig 25. And there you have it! Congratulations!!! The result is Product_A = 30.769231 Product_B = 46.153846 Max Profit = 375.3846155, which means that to achieve maximum profit, the carrier will have to load its truck with 30 boxes of Product A, 46 boxes of Product B and the maximum profit of $ 375.38 will be reached!
And finally, that’s all!
I hope you can be as surprised just as I am surprised by the 💪Power of Python!