equal
deleted
inserted
replaced
|
1 \documentclass[12pt]{article} |
|
2 \title{Solving Equations \& ODEs} |
|
3 \author{FOSSEE} |
|
4 \begin{document} |
|
5 \date{} |
|
6 \vspace{-1in} |
|
7 \begin{center} |
|
8 \LARGE{Solving Equations \& ODEs}\\ |
|
9 \large{FOSSEE} |
|
10 \end{center} |
|
11 \section{Solving linear equations} |
|
12 \begin{verbatim} |
|
13 In []: A = array([[3,2,-1], |
|
14 [2,-2,4], |
|
15 [-1, 0.5, -1]]) |
|
16 In []: b = array([[1], [-2], [0]]) |
|
17 In []: x = solve(A, b) |
|
18 In []: Ax = dot(A,x) |
|
19 In []: allclose(Ax, b) |
|
20 Out[]: True |
|
21 \end{verbatim} |
|
22 \section{Finding roots} |
|
23 \begin{verbatim} |
|
24 In []: coeffs = [1, 6, 13] |
|
25 In []: roots(coeffs) |
|
26 \end{verbatim} |
|
27 Finding the roots of a function |
|
28 \begin{verbatim} |
|
29 In []: fsolve(sin(x)+cos(x)**2, 0) |
|
30 \end{verbatim} |
|
31 \section{ODE} |
|
32 \begin{verbatim} |
|
33 In []: def epid(y, t): |
|
34 .... k, L = 0.00003, 25000 |
|
35 .... return k*y*(L-y) |
|
36 .... |
|
37 |
|
38 In []: t = arange(0, 12, 0.2) |
|
39 |
|
40 In []: y = odeint(epid, 250, t) |
|
41 |
|
42 In []: plot(t, y) |
|
43 \end{verbatim} |
|
44 \end{document} |