3D System — Extreme Points z=f(x,y)
Finding Extreme Points By Differentiation— #PySeries#Episode 24
Hi, in this post you’ll learn how to use a process known as differentiation to find a function’s derivative. In addition, you’ll learn other important calculus concepts known as critical points, extreme values. And More, we will Plotting a NumPy Polynomial with Matplotlib.
We are going to use Python and Geogebra.
Welcome!
01PyEx — Given the function z to respect to x and y, determine the extreme points:
Open a new notebook in your Colab now!
Let’s get down to work! Take the Derivatives of z to the respect of x and them y
%matplotlib inlineimport matplotlib.pyplot as pltimport numpy as npimport sympy as syx, y = sy.symbols('x y')Z = 3*x**2 + 2*x*y + y**2 + 10*x + 2*y + 1Zx = sy.diff(Z, x)Zy = sy.diff(Z, y)print(f'Zx = {Zx}\nZy = {Zy}')Zx = 6*x + 2*y + 10
Zy = 2*x + 2*y + 2
The first differentiation gives us 2 equation: a Linear System. Let’s solve it:
A = np.array([[6, 2], [2, 2]])b = np.array([-10, -2])x = np.linalg.solve(A,b)print(x)[-2. 1.]
So the points are x=−2; y=1
Here are The 3 Equations (y1, y2 and y3):
x, y = sy.symbols('x y')y1 = 3*x**2 + 2*x*y + y**2 + 10*x + 2*y + 1y2 = 6*x + 2*y + 10y3 = 2*x + 2*y + 2
Calculation of The First and the Second Partial Differentiation:
Discriminant — Formula
D=Zxx ∗ Zyy −( Zxy)2
It involves the second pure partial derivatives in product, subtracting the second mixed derivative squared
Zxx
#differentiate y1 with respect to xZx = sy.diff(y1, x)#returns resulting expression in factored form#this matters to our specific problem and looking#for some kind of structure in the expressionsy.factor(Zx)2(3x+y+5)
Now the second partial:
Zxx = sy.diff(Zx, x)print(f'Zxx={sy.factor(Zxx)}')Zxx=6
Zyy
#differentiate Zy with respect to yZy = sy.diff(y1, y)#returns resulting expression in factored form#this matters to our specific problem and looking#for some kind of structure in the expressionsy.factor(Zy)2(x+y+1)
And the second:
Zyy = sy.diff(Zy, y)print(f'Zyy={sy.factor(Zyy)}')Zyy=2
Zxy
#differentiate y1 with respect to xZx = sy.diff(y1, x)#returns resulting expression in factored form#this matters to our specific problem and looking#for some kind of structure in the expressionsy.factor(Zx)2(3x+y+5)
The second:
Zxy = sy.diff(Zx, y)print(f'Zxy={sy.factor(Zxy)}')Zxy=2
Discriminant — Formula
D= Zxx ∗ Zyy − (Zxy)^2D= 6 ∗ 2 − (2)^2 = 8D = 8
As D>0 and Zxx>0
Interpretation:
If D > 0 and Zxx < 0 ↦ MAX
If D > 0 and Zxx > 0 ↦ MIN
If D < 0 ↦ SADDLE
If D = 0 ↦NOT−CONCLUSIVE
So the points (-2,1) represents the Minimum
(see the graph above)
Plotting a polynomial in Geogebra
Equations:
z = 3x2+2xy+2y+10x+2y+1
Zx = 6x+2y+10=0 ↦ 6x+2y=−10
Zy = 2x+2y+2=0 ↦ 2x+2y=−2
See these Graph in Geogebra and video in Youtube:
Please, Watch the video to understand the three-dimensional figure and the point location.
You notice that the point found was on the xy plane. If you project the point (A) along the z-axis, you will see that the location of the point fits perfectly in 3D figure (C).
print("There you have it! Thank you very much! Python is awesome, doesn't it?")There you have it! Thank you very much! Python is awesome, doesn't it?
That’s All for this lecture!
See you in the next Python Episode!
See answer below!
Bye!!!!
Colab File link:)
Google Drive link:)
Geogebra Solution link:)
Video link:)
Credits & References
Geogebra Solution by J3
Youtube vid by J3
Decimal to Fraction Calculator by calculatorsoup.com
Exercícios Resolvidos Assunto: Integral Dupla (pdf) by Universidade Federal Fluminense (Brazil — Niterói — RJ)
Welcome to Calculus with Python’s documentation! — Calculus with Python by calc-again.readthedocs.io
LaTeX/Mathematics by wikibooks.org
Eddie Woo Vids by Eddie Woo
Taking Derivatives in Python by Dario Radečić
Plotting a polynomial in Python by stackoverflow.com
Three-Dimensional Plotting in Matplotlib by jakevdp.github.io
Finding Extreme Points by https://www.dataquest.io/m/159-finding-extreme-points/
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!
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 Data frame 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
21Episode#PySeries — Pandas — Pandas — One Hot Encoding (OHE) — Pandas Dataframe Examples: AI Secrets
22Episode#PySeries — Pandas — One Hot Encoding (OHE) — Pandas Dataframe Examples: AI Secrets
23Episode#PySeries — Double Integrals in Python — And Area Between Curves Resolutions
24Episode#PySeries — 3D System — Extreme Points z=f(x,y) — Finding Extreme Points(this one)