22 \begin{center} |
22 \begin{center} |
23 \LARGE{Solving Equations \& ODEs}\\ |
23 \LARGE{Solving Equations \& ODEs}\\ |
24 \large{FOSSEE} |
24 \large{FOSSEE} |
25 \end{center} |
25 \end{center} |
26 \section{Solving linear equations} |
26 \section{Solving linear equations} |
27 Condier following sets of equations:\\ |
27 Consider following sets of equations:\\ |
28 \begin{align*} |
28 \begin{align*} |
29 3x + 2y - z & = 1 \\ |
29 3x + 2y - z & = 1 \\ |
30 2x - 2y + 4z & = -2 \\ |
30 2x - 2y + 4z & = -2 \\ |
31 -x + \frac{1}{2}y -z & = 0 |
31 -x + \frac{1}{2}y -z & = 0 |
32 \end{align*}\\ |
32 \end{align*}\\ |
80 Out[95]: 1.5707963267948966 |
80 Out[95]: 1.5707963267948966 |
81 |
81 |
82 In [96]: expression(pi/3) |
82 In [96]: expression(pi/3) |
83 Out[96]: 0.90689968211710881 |
83 Out[96]: 0.90689968211710881 |
84 \end{lstlisting} |
84 \end{lstlisting} |
85 \subsection{Roots of non-linear eqations} |
85 \subsection{Roots of non-linear equations} |
86 For Finding the roots of a non linear equation(defined as $f(x)=0$), around a starting estimate we use \typ{fsolve}:\\ |
86 For Finding the roots of a non linear equation(defined as $f(x)=0$), around a starting estimate we use \typ{fsolve}:\\ |
87 \typ{In []: from scipy.optimize import fsolve}\\ |
87 \typ{In []: from scipy.optimize import fsolve}\\ |
88 \typ{fsolve} is not a part of \typ{pylab}, instead is a function in the \textbf{optimize} module of \textbf{scipy}, and hence we \textbf{import} it.\\ |
88 \typ{fsolve} is not a part of \typ{pylab}, instead is a function in the \textbf{optimize} module of \textbf{scipy}, and hence we \textbf{import} it.\\ |
89 %\typ{fsolve} takes first argument as name of function, which evaluates $f(x)$, whose roots one wants to find. And second argument is starting estimate, around which roots are found. |
89 %\typ{fsolve} takes first argument as name of function, which evaluates $f(x)$, whose roots one wants to find. And second argument is starting estimate, around which roots are found. |
90 For illustration, we want to find roots of equation: |
90 For illustration, we want to find roots of equation: |