avatarJ3

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5565

Abstract

hon the function that interpolates the points: <span class="hljs-attribute">A</span>(<span class="hljs-number">1</span>,<span class="hljs-number">5</span>), B(<span class="hljs-number">3</span>,<span class="hljs-number">4</span>), C(<span class="hljs-number">5</span>,<span class="hljs-number">9</span>) and D(<span class="hljs-number">9</span>,<span class="hljs-number">11</span>):</pre></div><p id="f1cb">Solution:</p><div id="0dd3"><pre><span class="hljs-attribute">from</span> scipy.interpolate import * <span class="hljs-attribute">x</span>=[<span class="hljs-number">1</span>,<span class="hljs-number">3</span>,<span class="hljs-number">5</span>,<span class="hljs-number">9</span>] <span class="hljs-attribute">y</span>=[<span class="hljs-number">5</span>,<span class="hljs-number">4</span>,<span class="hljs-number">9</span>,<span class="hljs-number">11</span>] <span class="hljs-attribute">f</span>=lagrange(x,y) <span class="hljs-attribute">print</span>(f)</pre></div><div id="03ee"><pre><span class="hljs-number">-0.1354</span> <span class="hljs-keyword">x</span>^<span class="hljs-number">3</span> + <span class="hljs-number">1.969</span> <span class="hljs-keyword">x</span>^<span class="hljs-number">2</span> - <span class="hljs-number">6.615</span> <span class="hljs-keyword">x</span> + <span class="hljs-number">9.781</span></pre></div><p id="1b7e"><b>08#PyEx </b>— Python — <a href="https://readmedium.com/linear-regressions-the-basics-1a633f351ec2"><b>Linear Regression</b></a><b>:</b></p><div id="84bb"><pre><span class="hljs-attribute">Which</span> best line that fits these points? <span class="hljs-attribute">A</span>(<span class="hljs-number">1</span>,<span class="hljs-number">5</span>), B(<span class="hljs-number">3</span>,<span class="hljs-number">4</span>), C(<span class="hljs-number">5</span>,<span class="hljs-number">9</span>), and D(<span class="hljs-number">9</span>,<span class="hljs-number">11</span>)</pre></div><p id="cdd9">Solution:</p><div id="b73e"><pre>import numpy as np import matplotlib.pyplot as pyp <span class="hljs-keyword">from</span> scipy import stats <span class="hljs-attribute">x</span>=np.array([1,2,3,4,5]) <span class="hljs-attribute">y</span>=np.array([180,120,150,190,210]) a,b,correlation,p,<span class="hljs-attribute">error</span>=stats.linregress(x,y) <span class="hljs-built_in">print</span>(‘Regression line: <span class="hljs-attribute">y</span>=%.2fx+%.2f’% (a,b)) <span class="hljs-built_in">print</span>(‘Correlation Coefficient: <span class="hljs-attribute">r</span>=%.2f’% correlation) <span class="hljs-attribute">f</span>=a*x+b</pre></div><div id="0e46"><pre><span class="hljs-attribute">Regression</span> line: y=<span class="hljs-number">13</span>.<span class="hljs-number">00</span>x+<span class="hljs-number">131</span>.<span class="hljs-number">00</span> <span class="hljs-attribute">Correlation</span> Coefficient: r=<span class="hljs-number">0</span>.<span class="hljs-number">58</span></pre></div><p id="d5f6"><b>09#PyEx </b>— Python —<b>Vectorial:</b></p><div id="6692"><pre><span class="hljs-attribute">Given</span> the vectors: <span class="hljs-attribute">u</span> = (<span class="hljs-number">7</span>, -<span class="hljs-number">22</span>, <span class="hljs-number">13</span>) and <span class="hljs-attribute">v</span> = (-<span class="hljs-number">1</span>, <span class="hljs-number">11</span>, <span class="hljs-number">23</span>); <span class="hljs-attribute">calculate</span> u.v and uXv:</pre></div><p id="abe9">Solution:</p><div id="9f16"><pre>import numpy as np u=np.array(<span class="hljs-string">[[7,-22,13]]</span>) v=np.array(<span class="hljs-string">[[-1,11,23]]</span>) uv=np.inner(u,v) uXv=np.cross(u,v) <span class="hljs-built_in">print</span>(uv) <span class="hljs-built_in">print</span>(uXv)</pre></div><div id="e277"><pre><span class="hljs-string">[[50]]</span> <span class="hljs-string">[[-649 -174 55]]</span></pre></div><p id="5d00"><b>10#PyEx </b>— Python — <b>Trigonometry:</b></p><div id="186d"><pre>What <span class="hljs-keyword">is</span> the angle which cosine <span class="hljs-keyword">is</span> <span class="hljs-number">-0.6544</span>?</pre></div><p id="4f31">Solution:</p><div id="a607"><pre><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np <span class="hljs-title">angle</span>=np.arccos(<span class="hljs-number">-0.6544</span>) <span class="hljs-title">np</span>.rad2deg(angle)</pre></div><div id="0bae"><pre><span class="hljs-attribute">130</span>.<span class="hljs-number">87417042181528</span></pre></div><p id="e826"><b>01Bonus#PyEx </b>— Python — <b>Derivative:</b></p><div id="195c"><pre>Can we calculate <span class="hljs-keyword">the</span> derivative <span class="hljs-keyword">in</span> python <span class="hljs-keyword">using</span>?</pre></div><p id="c032">Solution:</p><div id="55bb"><pre>Yes. <span class="hljs-keyword">use</span> <span class="hljs-keyword">lib</span> simpy <span class="hljs-keyword">and</span> diff command</pre></div><p id="d5b3"><b>02Bonus#PyEx </b>— Python — <b>Derivative:</b></p><div id="d442"><pre>Can we calculate <span class="hljs-keyword">the</span> integrate <span class="hljs-keyword">in</span> python <span class="hljs-keyword">using</span>?</pre></div><p id="9b68">Solution</p><div id="8cfa"><pre>Yes. <span class="hljs-keyword">Use</span> <span class="hljs-keyword">lib</span> simpy <span class="hljs-keyword">and</span> integrate command</pre></div><p id="a650">See you in next PySeries!</p><p id="f7f8">Bye, for now, o/</p><p id="1535"><a href="

Options

https://colab.research.google.com/drive/1xFPL9WYHfIk7MH7VTt9uQL20Yt0TrPfO?usp=sharing">Download all Files from the Colab Repo</a></p><h1 id="5f7a">References & Credits</h1><p id="d652">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 published while I’m studying Computer Engineer at <a href="https://www.googleadservices.com/pagead/aclk?sa=L&amp;ai=DChcSEwiFtdj5lovrAhUNDJEKHcjtBxkYABAAGgJjZQ&amp;ohost=www.google.com&amp;cid=CAESQOD25BK94W2RIpTcjmQbZc6oBfGMExYDk0VsQhHV92UNtjm_uu5i-Atd66h20hYQcJMpJAkDIT75IlsYtYh4gww&amp;sig=AOD64_2cC6J6H9kVwb_JXdIbzUuk9sLLDA&amp;q&amp;adurl&amp;ved=2ahUKEwi__s75lovrAhX8GbkGHdy1DHgQ0Qx6BAgNEAE">Escola Superior Politécnica Uninter</a><a href="https://emojipedia.org/person-lifting-weights/">🏋</a>!</p><h1 id="c335">Posts Related:</h1><p id="f92e">00Episode#<b>PySeries </b>— 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="17a8">01Episode#<b>PySeries </b>— Python — <a href="https://readmedium.com/python-for-engenniging-exercises-977fbe4d6d02">Python 4 Engineers — Exercises! An overview of the Opportunities Offered by Python in Engineering!</a></p><p id="1620">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="bf93">03Episode#<b>PySeries</b> — Python — Python 4 Engineers — More Exercises! — Another Round to Make Sure that Python is Really Amazing!</p><p id="6e2a">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="3e5f">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="dad7">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="1589">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="872f">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="7add">09Episode#<b>PySeries</b> — Python — Python 4 Engineers — Even More Exercises! — More Practicing Coding Questions in Python! (this one:)</p><p id="e269">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="7e0f">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="6ff5">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="50ec">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="9f10">14Episode#<b>PySeries</b> — Python — <a href="https://readmedium.com/pandas-operations-4b8f7a4b4139">Pandas — Pandas Dataframe Examples: Column Operations</a></p><p id="e380">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="cb30">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="dc95">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="5373">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="2f9d">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="33f2">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="7a9c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*WB9JQu1JjgidxVZi.png"><figcaption></figcaption></figure></article></body>

Python 4 Engineers — Even More Exercises!

More Practising Coding Questions in Python! — #PySeries#Episode 09

What follows are 10 Q&A plus 2 bonus:

Let’s get it on!

01#PyEx — Python — Imaginary Number:

Given z_1=3+4j and z_2=-5+14j. Compute z_1/z_2:

Solution:

z_1=3+4j
z_2=-5+14j
z_1/z_2
(0.18552036199095023-0.28054298642533937j)

02#PyEx — Python — Linear System:

What is the function in Python to solve Linear Systems?

Solution:

np.linalg.solve()

03#PyEx — Python — Definite Integral:

Using Python, compute integral of f(x) = x³+cos(x) in a range [0,3]:

Solution:

from sympy import *
x,f=symbols(“x f”)
init_printing()
f=x**3+cos(x)
integrate(f,(x,0,3))
sin(3)+4/81

04#PyEx — Python — Indefinite Integral:

Calculate the indefinite integral of the function:
 f’(x) = 6x⁵+cos(x);

Solution:

from sympy import *
x,f=symbols(“x f”)
init_printing()
f=6*x**5+cos(x)
integrate(f,x)
x^6+sin(x)

05#PyEx — Python — Vectorial:

What is the function in Python to solve vector products?

Solution:

uXv=np.cross(u,v)

06#PyEx — Python — Linear System:

Using python, solve the following linear system:
4x-3y+z=15
x+y+3z=27
2x+3y-4z=31

Solution:

import numpy as np
A=np.array([[4,-3,1],[1,1,3],[2,3,-4]])
b=np.array([[15],[27],[31]])
x=np.linalg.solve(A, b)
print(x)
[[9.2345679 ]
[8.35802469]
[3.13580247]]

07#PyEx — Python —Points Interpolations:

Get through python the function that interpolates the points: 
A(1,5), B(3,4), C(5,9) and D(9,11):

Solution:

from scipy.interpolate import *
x=[1,3,5,9]
y=[5,4,9,11]
f=lagrange(x,y)
print(f)
-0.1354 x^3 + 1.969 x^2 - 6.615 x + 9.781

08#PyEx — Python — Linear Regression:

Which best line that fits these points? 
A(1,5), B(3,4), C(5,9), and D(9,11)

Solution:

import numpy as np
import matplotlib.pyplot as pyp
from scipy import stats
x=np.array([1,2,3,4,5])
y=np.array([180,120,150,190,210])
a,b,correlation,p,error=stats.linregress(x,y)
print(‘Regression line: y=%.2fx+%.2f’% (a,b))
print(‘Correlation Coefficient: r=%.2f’% correlation)
f=a*x+b
Regression line: y=13.00x+131.00 
Correlation Coefficient: r=0.58

09#PyEx — Python —Vectorial:

Given the vectors: 
u = (7, -22, 13) and 
v = (-1, 11, 23); 
calculate u.v and uXv:

Solution:

import numpy as np
u=np.array([[7,-22,13]])
v=np.array([[-1,11,23]])
uv=np.inner(u,v)
uXv=np.cross(u,v)
print(uv)
print(uXv)
[[50]] 
[[-649 -174   55]]

10#PyEx — Python — Trigonometry:

What is the angle which cosine is -0.6544?

Solution:

import numpy as np
angle=np.arccos(-0.6544)
np.rad2deg(angle)
130.87417042181528

01Bonus#PyEx — Python — Derivative:

Can we calculate the derivative in python using?

Solution:

Yes. use lib simpy and diff command

02Bonus#PyEx — Python — Derivative:

Can we calculate the integrate in python using?

Solution

Yes. Use lib simpy and integrate command

See you in next PySeries!

Bye, for now, o/

Download all Files from the Colab Repo

References & Credits

Thank you, Mr. Ricardo A. Deckmann Zanardini — You are an Awesome Teacher! o/; Text published while I’m studying Computer Engineer at Escola Superior Politécnica Uninter🏋!

Posts Related:

00Episode#PySeries — Python — Jupiter Notebook Quick Start with VSCode — How to Set your Win10 Environment to use Jupiter Notebook

01Episode#PySeries — Python — Python 4 Engineers — Exercises! An overview of the Opportunities Offered by Python in Engineering!

02Episode#PySeries — Python — Geogebra Plus Linear Programming- We’ll Create a Geogebra program to help us with our linear programming

03Episode#PySeries — Python — Python 4 Engineers — More Exercises! — Another Round to Make Sure that Python is Really Amazing!

04Episode#PySeries — Python — Linear Regressions — The Basics — How to Understand Linear Regression Once and For All!

05Episode#PySeries — Python — NumPy Init & Python Review — A Crash Python Review & Initialization at NumPy lib.

06Episode#PySeries — Python — NumPy Arrays & Jupyter Notebook — Arithmetic Operations, Indexing & Slicing, and Conditional Selection w/ np arrays.

07Episode#PySeries — Python — Pandas — Intro & Series — What it is? How to use it?

08Episode#PySeries — Python — Pandas DataFrames — The primary Pandas data structure! It is a dict-like container for Series objects

09Episode#PySeries — Python — Python 4 Engineers — Even More Exercises! — More Practicing Coding Questions in Python! (this one:)

10Episode#PySeries — Python — Pandas — Hierarchical Index & Cross-section — Open your Colab notebook and here are the follow-up exercises!

11Episode#PySeries — Python — Pandas — Missing Data — Let’s Continue the Python Exercises — Filling & Dropping Missing Data

12Episode#PySeries — Python — Pandas — Group By — Grouping large amounts of data and compute operations on these groups

13Episode#PySeries — Python — Pandas — Merging, Joining & Concatenations — Facilities For Easily Combining Together Series or DataFrame

14Episode#PySeries — Python — Pandas — Pandas Dataframe Examples: Column Operations

15Episode#PySeries — Python — Python 4 Engineers — Keeping It In The Short-Term Memory — Test Yourself! Coding in Python, Again!

16Episode#PySeries — NumPy — NumPy Review, Again;) — Python Review Free Exercises

17Episode#PySeriesGenerators in Python — Python Review Free Hints

18Episode#PySeries — Pandas Review…Again;) — Python Review Free Exercise

19Episode#PySeriesMatlibPlot & Seaborn Python Libs — Reviewing theses Plotting & Statistics Packs

20Episode#PySeriesSeaborn Python Review — Reviewing theses Plotting & Statistics Packs

Python3
Numpy
Matplotlib
Scipy
Python 4 Engineer
Recommended from ReadMedium