Python for Science and Engg: Solving Equations & ODEs
34 pages
English

Python for Science and Engg: Solving Equations & ODEs

-

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
34 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

Python for Science and Engg:Solving Equations & ODEsFOSSEEDepartment of Aerospace EngineeringIIT BombaySciPy 2010, Introductory tutorialsDay 1, Session 6FOSSEE (IIT Bombay) Solving Equations & ODEs 1 / 34Solving linear equationsOutline1 Solving linear equations2 Finding Roots3 ODEs4 FFTsFOSSEE (IIT Bombay) Solving Equations & ODEs 2 / 34Solving linear equationsSolution of equationsConsider,3x+ 2y-z = 12x- 2y+ 4z =-21-x+ y-z = 02Solution:x = 1y =-2z =-2FOSSEE (IIT Bombay) Solving Equations & ODEs 3 / 34Solving linear equationsSolving using MatricesLet us now look at how to solve this using matricesIn []: A = array([[3,2,-1],[2,-2,4],[-1, 0.5, -1]])In []: b = array([1, -2, 0])In []: x = solve(A, b)FOSSEE (IIT Bombay) Solving Equations & ODEs 4 / 34Solving linear equationsSolution:In []: xOut[]: array([ 1., -2., -2.])FOSSEE (IIT Bombay) Solving Equations & ODEs 5 / 34Solving linear equationsLet’s check!In []: Ax = dot(A, x)In []: AxOut[]: array([ 1.00000000e+00, -2.00000000e+00,-1.11022302e-16])The last term in the matrix is actually 0!We can use allclose() to check.In []: allclose(Ax, b)Out[]: True10 mFOSSEE (IIT Bombay) Solving Equations & ODEs 6 / 34Solving linear equationsProblemSolve the set of equations:x+y+ 2z-w = 32x+ 5y-z- 9w =-32x+y-z+ 3w =-11x- 3y+ 2z+ 7w =-515 mFOSSEE (IIT Bombay) Solving Equations & ODEs 7 / 34Solving linear equationsSolutionUse solve()x =-5y = 2z = 3w = 0FOSSEE (IIT Bombay) ...

Sujets

Informations

Publié par
Publié le 27 juin 2011
Nombre de lectures 191
Langue English

Extrait

FOSSE
Python for Science and Engg: Solving Equations & ODEs
E(IITBom
FOSSEE
Department of Aerospace Engineering IIT Bombay
SciPy 2010, Introductory tutorials Day 1, Session 6
bay)SolvingqEuations&ODEs1/43
S)loivgnqEauitnoFOSSEE(IITBombay
FFTs
4
ODEs
3
Roots
2/EsODs&
2
Finding
Solving
linear equations
1
34linevingSoliltuOsnoitauqerane
ODEsons&
Consider,
Solution:
x=1 y= −2 z= −2
3/34
− = 2
3x+2yz=1 2x2y+4z= −2 x+1yz=0
oSontieqofnsioluSoeraetauqnivlnilgauitnosuatingEqolviay)SoBbmI(TISSEEOF
oSsnoitauqeraeniictrMangsiguinlvinglSolvseF&ODEs4/34
Let us now look at how to solve this usingsecmirta
array([[3,2,-1], [2,-2,4], [-1, 0.5, -1]]) array([1, -2, 0]) solve(A, b)
In []: b = In []: x =
In []: A =
vloSEgnitauqsnoiSEOSIIE(omTBy)ba
Solution:
In []: Out[]:
x array([
1.,
-2.,
-2.])
sitnoqeauenralingviolSDEs5/34ations&OvlniEguqmoab)yoSE(SETBIIOSF
eck!sch00.2-viollingSnoitteLsraenauqe(IEESSFO000000+e00,DO&s/6sEauqEnoitol)SngviBoITaymb34
In []: Ax = dot(A, x) In []: Ax Out[]: array([ 1.00000000e+00, -1 11022302e-16]) .
The last term in the matrix is actually0! We can uselaes)(clolto check.
In []: allclose(Ax, b) Out[]: True
10 m
loSmeorlbnoPsuatiareqlinevingSoy)baomqugEinlvSOFBTII(EES
15 m
Solve the set of equations:
x+y+2zw=3 2x+5yz9w= −3 2x+yz+3w= −11 x3y+2z+7w= −5
snO&taoi3/4ED7s
/8sE
Use
43
x y z w
= = = =
5 2 3 0
solve()
EEI(TIoBbmyaS)lovingEquations&ODnoituSSFOSgnilloivequanearsSoltion
)yoSvlniIIBTmoabFOSSEE(oostingRFind
Solving
linear equations
Outline
1
4/3
FFTs
ODEs
4
Roots
3
2
Finding
oitauqEg9sEDO&sn
3/4
6]
Calculates the roots of polynomials To calculate the roots ofx25x+6
In []: In []: Out[]:
coeffs = [1, -5, roots(coeffs) arra ([3., 2.])
tosgRintsooiPScroy:dniFEEI(OFSSnoitauqE01sEDO&saymbBoITngviol)S
vefsoliPy:stcSRgoodnniiF/11s
Finds the roots of a system of non-linear equations Input arguments - Function and initial estimate Returns the solution
43snoiEDO&
In []:fromscipy.optimizeimportfsolve
OSSEFTBomE(IIoSvlab)yuqtaniEg
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents