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) ...
Voir