SlideShare a Scribd company logo
1 of 11
Download to read offline
SCIPY-SYMPY
November 10, 2022
1 SCIPY
[2]: import scipy as sp
import numpy as np
import sympy as syp
import matplotlib.pyplot as plt
[6]: help(sp)
Help on package scipy:
NAME
scipy
DESCRIPTION
SciPy: A scientific computing package for Python
================================================
Documentation is available in the docstrings and
online at https://docs.scipy.org.
Contents
--------
SciPy imports all the functions from the NumPy namespace, and in
addition provides:
Subpackages
-----------
Using any of these subpackages requires an explicit import. For example,
``import scipy.cluster``.
::
cluster --- Vector Quantization / Kmeans
fft --- Discrete Fourier transforms
fftpack --- Legacy discrete Fourier transforms
integrate --- Integration routines
interpolate --- Interpolation Tools
1
io --- Data input and output
linalg --- Linear algebra routines
linalg.blas --- Wrappers to BLAS library
linalg.lapack --- Wrappers to LAPACK library
misc --- Various utilities that don't have
another home.
ndimage --- N-D image package
odr --- Orthogonal Distance Regression
optimize --- Optimization Tools
signal --- Signal Processing Tools
signal.windows --- Window functions
sparse --- Sparse Matrices
sparse.linalg --- Sparse Linear Algebra
sparse.linalg.dsolve --- Linear Solvers
sparse.linalg.dsolve.umfpack --- :Interface to the UMFPACK library:
Conjugate Gradient Method (LOBPCG)
sparse.linalg.eigen --- Sparse Eigenvalue Solvers
sparse.linalg.eigen.lobpcg --- Locally Optimal Block Preconditioned
Conjugate Gradient Method (LOBPCG)
spatial --- Spatial data structures and algorithms
special --- Special functions
stats --- Statistical Functions
Utility tools
-------------
::
test --- Run scipy unittests
show_config --- Show scipy build configuration
show_numpy_config --- Show numpy build configuration
__version__ --- SciPy version string
__numpy_version__ --- Numpy version string
PACKAGE CONTENTS
__config__
_build_utils (package)
_distributor_init
_lib (package)
cluster (package)
conftest
constants (package)
fft (package)
fftpack (package)
integrate (package)
interpolate (package)
io (package)
linalg (package)
misc (package)
2
ndimage (package)
odr (package)
optimize (package)
setup
signal (package)
sparse (package)
spatial (package)
special (package)
stats (package)
version
DATA
test = <scipy._lib._testutils.PytestTester object>
VERSION
1.7.3
FILE
/Users/mac21/opt/anaconda3/lib/python3.9/site-packages/scipy/__init__.py
1.1 INTERPOLACION
1.1.1 Univariable
[69]: from scipy.interpolate import *
%matplotlib notebook
[49]: #sp.interpolate.interp1d
nodos=np.linspace(0,1,6)
def f(t):
return np.sin(3*t)
x=np.linspace(0,1,100)
inter=interp1d(nodos,f(nodos),kind='cubic')
plt.figure(figsize=(6,5))
plt.plot(nodos,f(nodos),'ro',label='nodos')
plt.plot(x,f(x),'b-',label=r'$f(x)=sin(3x)$')
plt.plot(x,inter(x),'r--',label='interpolacion');
plt.legend();
3
[71]: nodos2=np.linspace(-5,5,51)
x2=np.linspace(-5,5,200)
def runge(y):
return 1./(1.+y**2)
inter2=BarycentricInterpolator(nodos2,runge(nodos2))
inter3=interp1d(nodos2,runge(nodos2),kind='cubic')
plt.figure(figsize=(6,5))
plt.plot(nodos2,runge(nodos2),'ro',label='nodos')
plt.plot(x2,runge(x2),'b-',label=r'$runge(x)=frac{1}{1+x^2}$')
plt.plot(x2,inter3(x2),'r--',label='interpolacion cubico');
plt.legend();
<IPython.core.display.Javascript object>
<IPython.core.display.HTML object>
[67]: aa=lagrange(nodos2,runge(nodos2))
print(aa)
10 9 8 7 6
-2.262e-05 x - 3.611e-20 x + 0.001267 x + 7.619e-18 x - 0.02441 x
5 4 3 2
4
+ 1.046e-16 x + 0.1974 x - 1.3e-16 x - 0.6742 x - 1.546e-16 x + 1
[ ]:
[72]: from mpl_toolkits.mplot3d.axes3d import Axes3D
[164]: xx=np.linspace(-3,3,50)
X,Y=np.meshgrid(xx,xx)
def g(x,y):
return np.sin(x)+np.sin(y)
Z=g(X,Y)
fig=plt.figure(figsize=(10,10))
ej1=plt.subplot2grid((2,2),(0,0),aspect='equal')
p1=ej1.pcolor(X,Y,Z)
fig.colorbar(p1)
C1=ej1.contour(X,Y,Z,colors='k')
ej1.clabel(C1)
ej1.set_title('Grafica del contorno')
#nodos
#np.random.seed(33)
nodos3=-3+6*np.random.rand(50,2)
xi=nodos3[:,0]
yi=nodos3[:,1]
zi=g(xi,yi)
ej2=plt.subplot2grid((2,2),(0,1),aspect='equal')
p2=ej2.pcolor(X,Y,Z)
fig.colorbar(p2)
ej2.scatter(xi,yi,c='k')
ej2.set_title('nube de puntos')
ej3=plt.subplot2grid((2,2),(1,0),projection='3d',colspan=2, rowspan=2)
ej3.plot_surface(X,Y,Z,alpha=0.4)
ej3.scatter(xi,yi,zi,s=22,c='r')
ej3.contour(X,Y,Z,zdir='z',offset=-4)
ej3.contour(X,Y,Z,zdir='x',offset=-5)
ej3.set_xlim3d(-5,3)
ej3.set_ylim3d(-3,5)
ej3.set_zlim3d(-4,2)
fig.tight_layout()
<IPython.core.display.Javascript object>
<IPython.core.display.HTML object>
/var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/3583880009.py:9
: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same
dimensions as C is deprecated since 3.3. Either specify the corners of the
quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or
5
set rcParams['pcolor.shading']. This will become an error two minor releases
later.
p1=ej1.pcolor(X,Y,Z)
/var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/3583880009.py:2
2: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same
dimensions as C is deprecated since 3.3. Either specify the corners of the
quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or
set rcParams['pcolor.shading']. This will become an error two minor releases
later.
p2=ej2.pcolor(X,Y,Z)
[160]: from scipy.interpolate import interp2d
ti = np.linspace(-3, 3, 10)
xi, yi = np.meshgrid(ti, ti)
zi = g(xi, yi)
inte2d = interp2d(xi, yi, zi, kind='linear')
plt.figure()
plt.axes().set_aspect('equal')
plt.pcolor(X, Y, inte2d(xx, xx))
plt.scatter(xi, yi,c='r',s=11)
CP = plt.contour(X, Y, inte2d(xx, xx), colors='k')
plt.clabel(CP)
plt.xlim(-3, 3)
plt.ylim(-3, 3)
plt.title('linear ')
<IPython.core.display.Javascript object>
<IPython.core.display.HTML object>
/var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/2983383542.py:8
: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same
dimensions as C is deprecated since 3.3. Either specify the corners of the
quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or
set rcParams['pcolor.shading']. This will become an error two minor releases
later.
plt.pcolor(X, Y, inte2d(xx, xx))
[160]: Text(0.5, 1.0, 'linear ')
[167]: ti = np.linspace(-3, 3, 10)
xi, yi = np.meshgrid(ti, ti)
zi = g(xi, yi)
interpola = RectBivariateSpline(ti, ti, zi, kx=3, ky=3)
plt.figure()
plt.axes().set_aspect('equal')
plt.pcolor(xi, yi, interpola(ti, ti))
CP = plt.contour(xi, yi, interpola(ti, ti), colors='k')
plt.clabel(CP)
6
plt.scatter(xi, yi,s=11,c='r')
plt.xlim(-3, 3)
plt.ylim(-3, 3)
<IPython.core.display.Javascript object>
<IPython.core.display.HTML object>
/var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/2885320853.py:7
: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same
dimensions as C is deprecated since 3.3. Either specify the corners of the
quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or
set rcParams['pcolor.shading']. This will become an error two minor releases
later.
plt.pcolor(xi, yi, interpola(ti, ti))
[167]: (-3.0, 3.0)
[ ]:
[ ]:
[ ]:
[ ]:
1.2 INTEGRACION
[168]: from scipy.integrate import *
𝑓(𝑥) = 𝑒−𝑥2
[199]: fun=lambda x : np.exp(-x**2)
print(quad(fun,0,2))
print(quad(lambda x : np.exp(-x**2),0,np.inf))
quad(lambda x : np.exp(-x**2),-np.inf,0)
np.pi/2
(0.8820813907624215, 9.793070696178202e-15)
(0.8862269254527579, 7.101318390472462e-09)
[199]: 1.5707963267948966
[200]: 0.8820813907624215*2
[200]: 1.764162781524843
7
∫
𝑥=𝑏
𝑥=𝑎
∫
𝑦=𝑔(𝑥)
𝑦=ℎ(𝑥)
𝑓(𝑥, 𝑦)𝑑𝑦𝑑𝑥
∫
1/2
0
∫
√1−4𝑦2
0
16𝑥𝑦 𝑑𝑦𝑑𝑥
[190]: f1=lambda x,y : 16*x*y
f2=lambda y : 0
f3=lambda y : np.sqrt(1-4*y**2)
dblquad(f1,0,0.5,f2,f3)
[190]: (0.5, 1.7092350012594845e-14)
[192]: nodos4=np.linspace(-2,1,100)
def inte(x):
return x**5
simps(nodos4,inte(nodos4))
[192]: -52.49987339719653
[193]: cumtrapz(nodos4,inte(nodos4))
[193]: array([ -4.66813575, -8.99065694, -12.98834443, -16.68102752,
-20.08761349, -23.22611658, -26.11368661, -28.76663709,
-31.20047282, -33.4299171 , -35.46893844, -37.33077682,
-39.02796944, -40.57237608, -41.97520392, -43.24703196,
-44.39783493, -45.43700675, -46.37338356, -47.21526618,
-47.97044226, -48.64620784, -49.24938848, -49.78635996,
-50.26306848, -50.6850504 , -51.05745154, -51.38504595,
-51.67225433, -51.92316183, -52.14153557, -52.33084151,
-52.494261 , -52.63470679, -52.75483857, -52.85707812,
-52.9436239 , -53.01646524, -53.07739604, -53.12802802,
-53.16980346, -53.20400758, -53.23178032, -53.25412776,
-53.27193301, -53.28596671, -53.29689696, -53.30529889,
-53.3116637 , -53.31640724, -53.31987819, -53.32236566,
-53.32410644, -53.32529173, -53.32607339, -53.32656975,
-53.32687098, -53.32704396, -53.32713665, -53.3271821 ,
-53.32720191, -53.32720923, -53.32721135, -53.32721175,
-53.32721179, -53.32721179, -53.32721179, -53.32721175,
-53.32721135, -53.32720923, -53.32720191, -53.3271821 ,
-53.32713665, -53.32704396, -53.32687098, -53.32656975,
-53.32607339, -53.32529173, -53.32410644, -53.32236566,
-53.31987819, -53.31640724, -53.3116637 , -53.30529889,
-53.29689696, -53.28596671, -53.27193301, -53.25412776,
-53.23178032, -53.20400758, -53.16980346, -53.12802802,
8
-53.07739604, -53.01646524, -52.9436239 , -52.85707812,
-52.75483857, -52.63470679, -52.494261 ])
∫
1
−1
sin(𝑥)
𝑥
𝑑𝑥
∫
∞
0
sin(𝑥)
𝑥
𝑑𝑥
[195]: def in2(x):
return np.sin(x)/x
quad(in2,0,np.inf)
/var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/1883490797.py:3
: IntegrationWarning: The integral is probably divergent, or slowly convergent.
quad(in2,0,np.inf)
[195]: (2.247867963468921, 3.2903230524472544)
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
1.3 OPTIMIZACION
[196]: from scipy.optimize import *
[ ]:
[ ]:
[ ]:
1.4 EDO
[ ]:
[ ]:
[ ]:
[ ]:
9
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
10
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
11

More Related Content

Similar to SCIPY-SYMPY Functions for Interpolation, Integration, Optimization & ODEs

Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnArnaud Joly
 
Hybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskitHybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskitVijayananda Mohire
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersKimikazu Kato
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruzrpmcruz
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...Andrey Karpov
 
Image Cryptography and Steganography
Image Cryptography and SteganographyImage Cryptography and Steganography
Image Cryptography and SteganographyMohammad Amin Amjadi
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITEgor Bogatov
 
What is the UML Class diagram for accident detection using CNN- i have.pdf
What is the UML Class diagram for accident detection using CNN- i have.pdfWhat is the UML Class diagram for accident detection using CNN- i have.pdf
What is the UML Class diagram for accident detection using CNN- i have.pdfanilagarwal8880432
 
Halide tutorial 2019
Halide tutorial 2019Halide tutorial 2019
Halide tutorial 2019Champ Yen
 
Python 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptxPython 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptxTseChris
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
Parallel R in snow (english after 2nd slide)
Parallel R in snow (english after 2nd slide)Parallel R in snow (english after 2nd slide)
Parallel R in snow (english after 2nd slide)Cdiscount
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyKimikazu Kato
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheetNishant Upadhyay
 

Similar to SCIPY-SYMPY Functions for Interpolation, Integration, Optimization & ODEs (20)

Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
Hybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskitHybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskit
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning Programmers
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruz
 
Profiling in Python
Profiling in PythonProfiling in Python
Profiling in Python
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
Python grass
Python grassPython grass
Python grass
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
 
Image Cryptography and Steganography
Image Cryptography and SteganographyImage Cryptography and Steganography
Image Cryptography and Steganography
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
What is the UML Class diagram for accident detection using CNN- i have.pdf
What is the UML Class diagram for accident detection using CNN- i have.pdfWhat is the UML Class diagram for accident detection using CNN- i have.pdf
What is the UML Class diagram for accident detection using CNN- i have.pdf
 
Halide tutorial 2019
Halide tutorial 2019Halide tutorial 2019
Halide tutorial 2019
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Python 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptxPython 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptx
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Parallel R in snow (english after 2nd slide)
Parallel R in snow (english after 2nd slide)Parallel R in snow (english after 2nd slide)
Parallel R in snow (english after 2nd slide)
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheet
 

Recently uploaded

定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一3sw2qly1
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Lucknow
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewingbigorange77
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Deliverybabeytanya
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...aditipandeya
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Personfurqan222004
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewing
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Person
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 

SCIPY-SYMPY Functions for Interpolation, Integration, Optimization & ODEs

  • 1. SCIPY-SYMPY November 10, 2022 1 SCIPY [2]: import scipy as sp import numpy as np import sympy as syp import matplotlib.pyplot as plt [6]: help(sp) Help on package scipy: NAME scipy DESCRIPTION SciPy: A scientific computing package for Python ================================================ Documentation is available in the docstrings and online at https://docs.scipy.org. Contents -------- SciPy imports all the functions from the NumPy namespace, and in addition provides: Subpackages ----------- Using any of these subpackages requires an explicit import. For example, ``import scipy.cluster``. :: cluster --- Vector Quantization / Kmeans fft --- Discrete Fourier transforms fftpack --- Legacy discrete Fourier transforms integrate --- Integration routines interpolate --- Interpolation Tools 1
  • 2. io --- Data input and output linalg --- Linear algebra routines linalg.blas --- Wrappers to BLAS library linalg.lapack --- Wrappers to LAPACK library misc --- Various utilities that don't have another home. ndimage --- N-D image package odr --- Orthogonal Distance Regression optimize --- Optimization Tools signal --- Signal Processing Tools signal.windows --- Window functions sparse --- Sparse Matrices sparse.linalg --- Sparse Linear Algebra sparse.linalg.dsolve --- Linear Solvers sparse.linalg.dsolve.umfpack --- :Interface to the UMFPACK library: Conjugate Gradient Method (LOBPCG) sparse.linalg.eigen --- Sparse Eigenvalue Solvers sparse.linalg.eigen.lobpcg --- Locally Optimal Block Preconditioned Conjugate Gradient Method (LOBPCG) spatial --- Spatial data structures and algorithms special --- Special functions stats --- Statistical Functions Utility tools ------------- :: test --- Run scipy unittests show_config --- Show scipy build configuration show_numpy_config --- Show numpy build configuration __version__ --- SciPy version string __numpy_version__ --- Numpy version string PACKAGE CONTENTS __config__ _build_utils (package) _distributor_init _lib (package) cluster (package) conftest constants (package) fft (package) fftpack (package) integrate (package) interpolate (package) io (package) linalg (package) misc (package) 2
  • 3. ndimage (package) odr (package) optimize (package) setup signal (package) sparse (package) spatial (package) special (package) stats (package) version DATA test = <scipy._lib._testutils.PytestTester object> VERSION 1.7.3 FILE /Users/mac21/opt/anaconda3/lib/python3.9/site-packages/scipy/__init__.py 1.1 INTERPOLACION 1.1.1 Univariable [69]: from scipy.interpolate import * %matplotlib notebook [49]: #sp.interpolate.interp1d nodos=np.linspace(0,1,6) def f(t): return np.sin(3*t) x=np.linspace(0,1,100) inter=interp1d(nodos,f(nodos),kind='cubic') plt.figure(figsize=(6,5)) plt.plot(nodos,f(nodos),'ro',label='nodos') plt.plot(x,f(x),'b-',label=r'$f(x)=sin(3x)$') plt.plot(x,inter(x),'r--',label='interpolacion'); plt.legend(); 3
  • 4. [71]: nodos2=np.linspace(-5,5,51) x2=np.linspace(-5,5,200) def runge(y): return 1./(1.+y**2) inter2=BarycentricInterpolator(nodos2,runge(nodos2)) inter3=interp1d(nodos2,runge(nodos2),kind='cubic') plt.figure(figsize=(6,5)) plt.plot(nodos2,runge(nodos2),'ro',label='nodos') plt.plot(x2,runge(x2),'b-',label=r'$runge(x)=frac{1}{1+x^2}$') plt.plot(x2,inter3(x2),'r--',label='interpolacion cubico'); plt.legend(); <IPython.core.display.Javascript object> <IPython.core.display.HTML object> [67]: aa=lagrange(nodos2,runge(nodos2)) print(aa) 10 9 8 7 6 -2.262e-05 x - 3.611e-20 x + 0.001267 x + 7.619e-18 x - 0.02441 x 5 4 3 2 4
  • 5. + 1.046e-16 x + 0.1974 x - 1.3e-16 x - 0.6742 x - 1.546e-16 x + 1 [ ]: [72]: from mpl_toolkits.mplot3d.axes3d import Axes3D [164]: xx=np.linspace(-3,3,50) X,Y=np.meshgrid(xx,xx) def g(x,y): return np.sin(x)+np.sin(y) Z=g(X,Y) fig=plt.figure(figsize=(10,10)) ej1=plt.subplot2grid((2,2),(0,0),aspect='equal') p1=ej1.pcolor(X,Y,Z) fig.colorbar(p1) C1=ej1.contour(X,Y,Z,colors='k') ej1.clabel(C1) ej1.set_title('Grafica del contorno') #nodos #np.random.seed(33) nodos3=-3+6*np.random.rand(50,2) xi=nodos3[:,0] yi=nodos3[:,1] zi=g(xi,yi) ej2=plt.subplot2grid((2,2),(0,1),aspect='equal') p2=ej2.pcolor(X,Y,Z) fig.colorbar(p2) ej2.scatter(xi,yi,c='k') ej2.set_title('nube de puntos') ej3=plt.subplot2grid((2,2),(1,0),projection='3d',colspan=2, rowspan=2) ej3.plot_surface(X,Y,Z,alpha=0.4) ej3.scatter(xi,yi,zi,s=22,c='r') ej3.contour(X,Y,Z,zdir='z',offset=-4) ej3.contour(X,Y,Z,zdir='x',offset=-5) ej3.set_xlim3d(-5,3) ej3.set_ylim3d(-3,5) ej3.set_zlim3d(-4,2) fig.tight_layout() <IPython.core.display.Javascript object> <IPython.core.display.HTML object> /var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/3583880009.py:9 : MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or 5
  • 6. set rcParams['pcolor.shading']. This will become an error two minor releases later. p1=ej1.pcolor(X,Y,Z) /var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/3583880009.py:2 2: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later. p2=ej2.pcolor(X,Y,Z) [160]: from scipy.interpolate import interp2d ti = np.linspace(-3, 3, 10) xi, yi = np.meshgrid(ti, ti) zi = g(xi, yi) inte2d = interp2d(xi, yi, zi, kind='linear') plt.figure() plt.axes().set_aspect('equal') plt.pcolor(X, Y, inte2d(xx, xx)) plt.scatter(xi, yi,c='r',s=11) CP = plt.contour(X, Y, inte2d(xx, xx), colors='k') plt.clabel(CP) plt.xlim(-3, 3) plt.ylim(-3, 3) plt.title('linear ') <IPython.core.display.Javascript object> <IPython.core.display.HTML object> /var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/2983383542.py:8 : MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later. plt.pcolor(X, Y, inte2d(xx, xx)) [160]: Text(0.5, 1.0, 'linear ') [167]: ti = np.linspace(-3, 3, 10) xi, yi = np.meshgrid(ti, ti) zi = g(xi, yi) interpola = RectBivariateSpline(ti, ti, zi, kx=3, ky=3) plt.figure() plt.axes().set_aspect('equal') plt.pcolor(xi, yi, interpola(ti, ti)) CP = plt.contour(xi, yi, interpola(ti, ti), colors='k') plt.clabel(CP) 6
  • 7. plt.scatter(xi, yi,s=11,c='r') plt.xlim(-3, 3) plt.ylim(-3, 3) <IPython.core.display.Javascript object> <IPython.core.display.HTML object> /var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/2885320853.py:7 : MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later. plt.pcolor(xi, yi, interpola(ti, ti)) [167]: (-3.0, 3.0) [ ]: [ ]: [ ]: [ ]: 1.2 INTEGRACION [168]: from scipy.integrate import * 𝑓(𝑥) = 𝑒−𝑥2 [199]: fun=lambda x : np.exp(-x**2) print(quad(fun,0,2)) print(quad(lambda x : np.exp(-x**2),0,np.inf)) quad(lambda x : np.exp(-x**2),-np.inf,0) np.pi/2 (0.8820813907624215, 9.793070696178202e-15) (0.8862269254527579, 7.101318390472462e-09) [199]: 1.5707963267948966 [200]: 0.8820813907624215*2 [200]: 1.764162781524843 7
  • 8. ∫ 𝑥=𝑏 𝑥=𝑎 ∫ 𝑦=𝑔(𝑥) 𝑦=ℎ(𝑥) 𝑓(𝑥, 𝑦)𝑑𝑦𝑑𝑥 ∫ 1/2 0 ∫ √1−4𝑦2 0 16𝑥𝑦 𝑑𝑦𝑑𝑥 [190]: f1=lambda x,y : 16*x*y f2=lambda y : 0 f3=lambda y : np.sqrt(1-4*y**2) dblquad(f1,0,0.5,f2,f3) [190]: (0.5, 1.7092350012594845e-14) [192]: nodos4=np.linspace(-2,1,100) def inte(x): return x**5 simps(nodos4,inte(nodos4)) [192]: -52.49987339719653 [193]: cumtrapz(nodos4,inte(nodos4)) [193]: array([ -4.66813575, -8.99065694, -12.98834443, -16.68102752, -20.08761349, -23.22611658, -26.11368661, -28.76663709, -31.20047282, -33.4299171 , -35.46893844, -37.33077682, -39.02796944, -40.57237608, -41.97520392, -43.24703196, -44.39783493, -45.43700675, -46.37338356, -47.21526618, -47.97044226, -48.64620784, -49.24938848, -49.78635996, -50.26306848, -50.6850504 , -51.05745154, -51.38504595, -51.67225433, -51.92316183, -52.14153557, -52.33084151, -52.494261 , -52.63470679, -52.75483857, -52.85707812, -52.9436239 , -53.01646524, -53.07739604, -53.12802802, -53.16980346, -53.20400758, -53.23178032, -53.25412776, -53.27193301, -53.28596671, -53.29689696, -53.30529889, -53.3116637 , -53.31640724, -53.31987819, -53.32236566, -53.32410644, -53.32529173, -53.32607339, -53.32656975, -53.32687098, -53.32704396, -53.32713665, -53.3271821 , -53.32720191, -53.32720923, -53.32721135, -53.32721175, -53.32721179, -53.32721179, -53.32721179, -53.32721175, -53.32721135, -53.32720923, -53.32720191, -53.3271821 , -53.32713665, -53.32704396, -53.32687098, -53.32656975, -53.32607339, -53.32529173, -53.32410644, -53.32236566, -53.31987819, -53.31640724, -53.3116637 , -53.30529889, -53.29689696, -53.28596671, -53.27193301, -53.25412776, -53.23178032, -53.20400758, -53.16980346, -53.12802802, 8
  • 9. -53.07739604, -53.01646524, -52.9436239 , -52.85707812, -52.75483857, -52.63470679, -52.494261 ]) ∫ 1 −1 sin(𝑥) 𝑥 𝑑𝑥 ∫ ∞ 0 sin(𝑥) 𝑥 𝑑𝑥 [195]: def in2(x): return np.sin(x)/x quad(in2,0,np.inf) /var/folders/v1/vg27shm94bz102sndw5m5pc80000gn/T/ipykernel_37019/1883490797.py:3 : IntegrationWarning: The integral is probably divergent, or slowly convergent. quad(in2,0,np.inf) [195]: (2.247867963468921, 3.2903230524472544) [ ]: [ ]: [ ]: [ ]: [ ]: 1.3 OPTIMIZACION [196]: from scipy.optimize import * [ ]: [ ]: [ ]: 1.4 EDO [ ]: [ ]: [ ]: [ ]: 9
  • 10. [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: 10
  • 11. [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: [ ]: 11