0% found this document useful (0 votes)
24 views52 pages

Lecture 9

Uploaded by

Rebecca Morris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views52 pages

Lecture 9

Uploaded by

Rebecca Morris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

ENGG1810/9810

ENGG1810/9810
Introduction to Engineering Computing
Week 9: Application I

Dr. Imdad Ullah


Faculty of Engineering
ENGG1810/9810

COMMONWEALTH OF AUSTRALIA

Copyright Regulations 1969

WARNING

This material has been reproduced and communicated to you by or on behalf of


the University of Sydney pursuant to Part VB of the Copyright Act 1968 (the Act).

The material in this communication may be subject to copyright under the Act.
Any further reproduction or communication of this material by you may be the
subject of copyright protection under the Act.

Do not remove this notice.


INTRODUCTION
ENGG1810/9810

What will you learn in this course?


Week 1: Introduction to Python

Week 2: Storing Data and Making Decisions Programming


Week 3: Repeating Actions I Basics

Week 4: Repeating Actions II

Week 5: Functions I
Week 6: Functions II Functions
Week 7: Libraries and Modules I
and Packages

Week 8: Libraries and Modules II

Week 9: Application I

Week 10: Application II Advanced


Week 11: Case Study I
Topics

Week 12: Case Study II

Week 13: Revision and Exam Guide


INTRODUCTION
ENGG1810/9810

From Week 1 to Week 8


Week 1: Introduction to Python

Week 2: Storing Data and Making Decisions Programming


Week 3: Repeating Actions I Basics

Week 4: Repeating Actions II

Week 5: Functions I
Week 6: Functions II Functions
Week 7: Libraries and Modules I
and Packages

Week 8: Libraries and Modules II


INTRODUCTION
ENGG1810/9810

From Week 9 to Week 12


Imdad! what do we
learn from this week?

Week 9: Application I

Week 10: Application II Advanced


Week 11: Case Study I
Topics

Week 12: Case Study II

Week 13: Revision and Exam Guide


INTRODUCTION
ENGG1810/9810

From Week 1 to Week 8


Imdad! Why course
structure in Sem1 and
Sem2 is different?

We have learned all basic concepts from Week 1 to 8,


and will do the advanced contents from Week 9 to 12.

Let me show the Content Coverage Comparison between


Semester 1 and Semester 2. (presented during the lecture)
Week 9: Application I

Week 10: Application II Advanced


Week 11: Case Study I
Topics

Week 12: Case Study II

Week 13: Revision and Exam Guide


ENGG1810/9810

More Graph Drawing Application!


Python Matplotlib
Some Recaps
Useful Matplotlib Tips
Interpolation
Linear Interpolation
Cubic Spline Interpolation
Extrapolation
3D plots
Creating 3D axes
Adding data to 3D plot
Surface and Wire Plot
ENGG1810/9810

Python More with Matplotlib


Will analyse and demo this during the lecture please check the colab and lecture recording
- Review/newly learn how to use subplots, np.linspace, grid, annotate, xkcd

https://colab.research.google.com/drive/1ZcHROLwBYTDC5AUnuCnWTZI2cTgHfA74?usp=sharing
ENGG1810/9810

Python More with Matplotlib


Will analyse and demo this during the lecture please check the colab and lecture recording
- Review/newly learn how to use subplots, np.linspace, grid, annotate, xkcd

https://colab.research.google.com/drive/1ZcHROLwBYTDC5AUnuCnWTZI2cTgHfA74?usp=sharing
ENGG1810/9810

Python More with Matplotlib


Will analyse and demo this during the lecture please check the colab and lecture recording
- Review/newly learn how to use subplots, plot np.linspace, grid, annotate, xkcd, legend

https://colab.research.google.com/drive/1ZcHROLwBYTDC5AUnuCnWTZI2cTgHfA74?usp=sharing
s

n y
Fuge

tinge
grid

Yxation
Hation

Point

a
style
ENGG1810/9810

More Graph Drawing Application!


Python Matplotlib
Some Recaps
Useful Matplotlib Tips
Interpolation
Linear Interpolation
Cubic Spline Interpolation
Extrapolation
3D plots
Creating 3D axes
Adding data to 3D plot
Surface and Wire Plot
ENGG1810/9810

Python Missing Data

I have a Pikachu that uses a ThunderBolt skill every hour.


I have been detecting the voltage of electricity for last 5 hours.

1st hour: 100K volts


2nd hour: 90K volts
3rd hour: 101K volts
4th hour: 98K volts
5th hour: 100K volts
ENGG1810/9810

Python Missing Data


I have been detecting the voltage of electricity for last 5 hours.
1st hour: 100K volts
2nd hour: 90K volts
3rd hour: 101K volts We can draw like this!
4th hour: 98K volts
5th hour: 100K volts

A Monnected
ENGG1810/9810

Python Missing Data


Hours Voltages
1 100
2 90
3 101 We can draw like this!
4 98
5 100
ENGG1810/9810

What if we change the hour to time? Python Missing Data


time
Hours Voltages
1 100
2 90
3 101
4 98
5 100

Let x-axis be the time, and y-axis be a voltage: y = f(t)


We have measured y at 5 different time points.
What is the value of y when the time is 1.5?
What is the value of y when the time is 2.4?

If we are given a set of data that fit a pattern,


time
can we estimate values that are missing?
ENGG1810/9810

What if we change the hour to time? Python Interpolation


time
Hours Voltages
1 100
2 90
3 101
4 98 We can use Interpolation!
5 100 Method for estimating an unknown value
between known values.

Let x-axis be the time, and y-axis be a voltage: y = f(t)


We have measured y at 5 different time points.
What is the value of y when the time is 1.5?
What is the value of y when the time is 2.4?

time
ENGG1810/9810

Python Interpolation
Interpolation is a method for estimating an unknown value between known values.
There are two common interpolation methods:

Linear Interpolation Cubic spline interpolation


ENGG1810/9810

The core library for math, science, and engineering

Python Scipy

SciPy - open-source library of Python modules for mathematics, science and engineering.

To use it, we can use the keyword import module:

import scipy

SciPy Reference
http://scipy.github.io/devdocs/dev/
ENGG1810/9810

Pikachu, come on again!

o: produce a small circle marker


- : produce a solid line to connect the markers.
ENGG1810/9810

Python Linear Interpolation


Use interp1d()from scipy.interpolate module

https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html#scipy.interpolate.interp1d
ENGG1810/9810

Python Linear Interpolation


Use interp1d()from scipy.interpolate module

https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html#scipy.interpolate.interp1d
ENGG1810/9810

Python Linear Interpolation

To calculate approximate value of y when x is 2.4:


ENGG1810/9810

More Graph Drawing Application!


Python Matplotlib
Some Recaps
Useful Matplotlib Tips
Interpolation
Linear Interpolation
Cubic Spline Interpolation
Extrapolation
3D plots
Creating 3D axes
Adding data to 3D plot
Surface and Wire Plot
ENGG1810/9810

Python Cubic Spline Interpolation

Ok! How can we try it in Python?

Not-a-Knot boundary
https://timodenk.com/blog/cubic-spline-interpolation/
https://tools.timodenk.com/cubic-spline-interpolation
ENGG1810/9810

Python Cubic Spline Interpolation


Use CubicSpline()from scipy.interpolate module

https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.CubicSpline.html
ENGG1810/9810

Python Linear VS Cubic Spline Interpolation


Can you see the difference?

Linear Interpolation Cubic spline interpolation


ENGG1810/9810

Python Linear VS Cubic Spline Interpolation


We can add more points!
ENGG1810/9810

Python Linear VS Cubic Spline Interpolation


Now! Can you see the difference?

Linear Interpolation Cubic spline interpolation


ENGG1810/9810

More Graph Drawing Application!


Python Matplotlib
Some Recaps
Useful Matplotlib Tips
Interpolation
Linear Interpolation
Cubic Spline Interpolation
Extrapolation
3D plots
Creating 3D axes
3D Line Graph with Numpy
Surface and Wireframe Plot
ENGG1810/9810

Python Linear Interpolation


What if I would like to estimate a value outside of the range of known values?

Can I estimate x = 6
using linear interpolation?
ENGG1810/9810

Python Linear Interpolation


What if I would like to estimate a value outside of the range of known values?

Can I estimate x = 6
using linear interpolation?

out ofrange
ENGG1810/9810

Python Extrapolation
Method of estimating a value outside of the range of known values

We cannot use linear interpolation to perform extrapolation

Instead, we have to fit a curve (trendline) to our known data


This curve can be extended to the new x values, allowing us to estimate their y values

Curve fitting can also be used for interpolation

Oh! Maybe I can use


Cubic Spline Interpolation!
ENGG1810/9810

Python Extrapolation
Method of estimating a value outside of the range of known values

Yay!

ate
out
y howoften
ENGG1810/9810

Python Extrapolation
Method of estimating a value outside of the range of known values

Yay!

Spline interpolation yields a piecewise continuous function


composed of many polynomials (cubic polynomials) to model
the data set.
ENGG1810/9810

More Graph Drawing Application!


Python Matplotlib
Some Recaps
Useful Matplotlib Tips
Interpolation
Linear Interpolation
Cubic Spline Interpolation
Extrapolation
3D plots
Creating 3D axes
3D Line Graph with Numpy
Surface and Wireframe Plot
ENGG1810/9810

Python 3D plots!

2D Plot VS 3D Plot

here in 3D!
We have been drawing a
lot here in 2D!

Matplitlib mplot3d Reference


https://matplotlib.org/stable/tutorials/toolkits/mplot3d.html
ENGG1810/9810

Python 3D plots!
3D Axes (of class Axes3D) are created by passing
the projection="3d" keyword argument to Figure.add_subplot:

Ok! We are ready!


Add some data please!

Matplitlib mplot3d Reference


https://matplotlib.org/2.0.2/mpl_toolkits/mplot3d/tutorial.html
ENGG1810/9810

Python Numpy Array: Draw Sin/Cos Graph in 2D

https://numpy.org/doc/stable/reference/generated/numpy.sin.html?highlight=sin#numpy.sin
https://numpy.org/doc/stable/reference/generated/numpy.cos.html?highlight=cos#numpy.cos
ENGG1810/9810

Python Line Graph: Draw Sin Graph in 3D

x
y: vector of zeros doesnt
z: sin(x) show a
yvain
ENGG1810/9810

Python Line Graph: Draw Sin/Cos Graph in 3D Parametric Curve


ENGG1810/9810

Python Line Graph: Draw Sin/Cos Graph in 3D Parametric Curve

.plot(x, y, z, any options): You can plot 2D or 3D data


x = 1D array-like; x coordinates of vertices.
y = 1D array-like; y coordinates of vertices.
z = float or 1D array-like; z coordinates of vertices; either one for https://matplotlib.org/stable/tutorials/toolkits/mplot3d.html#line-plots
all points or one for each point. https://matplotlib.org/stable/tutorials/toolkits/mplot3d.html#scatter-plots
ENGG1810/9810

More Graph Drawing Application!


Python Matplotlib
Some Recaps
Useful Matplotlib Tips
Interpolation
Linear Interpolation
Cubic Spline Interpolation
Extrapolation
3D plots
Creating 3D axes
3D Line Graph with Numpy
Surface and Wireframe Plot
ENGG1810/9810

Python Surface Plot


Useful to visualize a graph of some relationship z = f(x, y)
All (x, y) pairs must be given - Difficult to specify all (x, y) combinations using only vectors

We need np.meshgrid(x, y)
Generate a mesh listing all possible
combinations of x and y values given
lists/arrays of x and y.
ENGG1810/9810

Python Surface Plot with meshgrid


Useful to visualize a graph of some relationship z = f(x, y)
All (x, y) pairs must be given by using np.meshgrid(x, y)

Generate a mesh listing all possible


combinations of x and y values given
lists/arrays of x and y. https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html
ENGG1810/9810

Python Surface Plot

2D arrays! Down-sampling stride


in each direction

https://matplotlib.org/stable/tutorials/toolkits/mplot3d.html#surface-plots
https://matplotlib.org/stable/tutorials/colors/colormaps.html
ENGG1810/9810

Python WireframePlot
No coloured facets!

https://matplotlib.org/stable/tutorials/toolkits/mplot3d.html#wireframe-plots
ENGG1810/9810

THANKS FOR
WATCHING
Good luck in studying

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy