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+bRegression 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#PySeries — Generators in Python — Python Review Free Hints
18Episode#PySeries — Pandas Review…Again;) — Python Review Free Exercise
19Episode#PySeries — MatlibPlot & Seaborn Python Libs — Reviewing theses Plotting & Statistics Packs
20Episode#PySeries — Seaborn Python Review — Reviewing theses Plotting & Statistics Packs