2018-19
In [1]:
def simple_interest (p,r,t):
i=(p*t*r)/100
print("interest=",i)
return i
In [2]:
def simple_amount (p,r,t):
a=p*(1+(t*r)/100)
print("amount=",a)
return a
In [3]:
def simple_principal(a,t,r):
p=a/(1+(r*t)/100)
print("principle=",sp)
return sp
In [4]:
def simple_rate(a,p,t):
sp=a*(1+(r*t)/100)
print("rate=",sr)
return sp
In [5]:
def compound_interest(p,r,t):
cmi=p(1+(r/100))**t-1
print("compound interest=",cmi)
return cmi
In [6]:
def compound_principal(a,r,t):
cmp=(a)*(1+r/100)**t
print("compound principal=",cmp)
return cmp
In [7]:
def compound_amount(p,r,t):
cma=p*(1+r/100)**t
print("compound amount=",cma)
return cma
In [8]:
def cont_interest(p,r,t):
cni=((p*(1+r/100*n)))**(n*t)
print("continous interest=",cni)
return cni
In [9]:
def cont_amount(p,r,t,n):
def cont_amount(p,r,t,n):
cna=(p*(1+r/(100*n)))**(n*t)
print("continous amount=",cna)
return cna
In [10]:
def cont_principal(a,r,t,n):
cnp(a*(1+r/(100*n)))**(-(n-t))
print("continous principal=",cnp)
return cnp
In [11]:
In [12]:
x=complex(2)
print ("complex number:",x)
print("complex number-real part:",x.real)
print("complex number-imaginary part:",x.imag)
In [13]:
5.0
the real part of complex number is:3.0
In [1]:
#python code to demostrate the working of phase(),abs()
import cmath
#initialising real numbers
x=-1
y=0
#converting to complex number
z=complex(x,y)
#printing the phase of the complex number using phase
print(z.real)
print("the phase for arugement of complex number using phase()")
print(cmath.phase(z))
#printing the magnitude of the complex number
print("the magnitude of complex number is :",end="")
print(abs(z))
-1.0
the phase for arugement of complex number using phase()
3.141592653589793
the magnitude of complex number is :1.0
In [15]:
#python code to demostrate the working of polar(),rect()
import cmath
#initialising real numbers
x=1
y=1
#converting to complex number
z=complex(x,y)
#converting complex numbers into polar form using polar()
w=cmath.polar(z)
#printing modules and arguments of polar complex form
print("the modules and arguements of polar complex form in:",end="")
#converting complex number into rectangle using rect()
v=cmath.rect(1.4142140,.785378)
#printing the rectangke form of complex number
print("the rectangluar form of complex number is:",end="")
print(v)
the modules and arguements of polar complex form in:the rectangluar form of complex number is:(1.000020
4726493573+0.9999801458419842j)
In [16]:
29-11 , 4 -12
In [17]:
import matplotlib.pyplot as plt
import numpy as np
In [18]:
a=np.linspace(0,2,100)
b=np.linspace(0,2,100)
In [37]:
X,Y=np.meshgrid(a,b)
Z=((X+Y*1j)**2-1)/(x+1j*Y+1)**2
In [20]:
Z
Out[20]:
array([[-0.25 +0. j, -0.24989797+0. j,
-0.24959188+0. j, ..., 0.71000408+0. j,
0.72990001+0. j, 0.75 +0. j],
[-0.25002549+0.00505154j, -0.24991937+0.00525347j,
-0.24960925+0.00545129j, ..., 0.71008459+0.00544931j,
0.72997855+0.00525145j, 0.75007651+0.00504947j],
[-0.25010174+0.01010925j, -0.24998336+0.01051275j,
-0.24966116+0.01090801j, ..., 0.71032595+0.0108922 j,
0.73021401+0.01049661j, 0.75030588+0.01009277j],
...,
[-0.01259762+0.61721919j, -0.00249976+0.61737322j,
0.00760024+0.61742316j, ..., 0.97678718+0.14751383j,
0.98709112+0.13757106j, 0.99739719+0.1275242 j],
[-0.00630637+0.62116098j, 0.00379413+0.62121199j,
0.01389567+0.62115994j, ..., 0.9783131 +0.14625735j,
0.98851508+0.13631145j, 0.99871811+0.1262625 j],
[ 0. +0.625 j, 0.01010101+0.62494898j,
0.02020202+0.62479594j, ..., 0.97979798+0.14499796j,
0.98989899+0.13504999j, 1. +0.125 j]])
In [21]:
X,Y
Out[21]:
(array([[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
...,
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ]]),
array([[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0.02020202, 0.02020202, 0.02020202, ..., 0.02020202, 0.02020202,
0.02020202],
[0.04040404, 0.04040404, 0.04040404, ..., 0.04040404, 0.04040404,
0.04040404],
...,
[1.95959596, 1.95959596, 1.95959596, ..., 1.95959596, 1.95959596,
1.95959596],
[1.97979798, 1.97979798, 1.97979798, ..., 1.97979798, 1.97979798,
1.97979798],
[2. , 2. , 2. , ..., 2. , 2. ,
2. ]]))
In [22]:
plt.contour(X,Y,Z)
Out[22]:
<matplotlib.contour.QuadContourSet at 0x1cfb8144d30>
In [27]:
plt.contour(X,Y,Z.real)
plt.contour(X,Y,Z.imag)
Out[27]:
<matplotlib.contour.QuadContourSet at 0x1cfb833d470>
In [26]:
plt.contour(X,Y,Z.imag)
Out[26]:
<matplotlib.contour.QuadContourSet at 0x1cfb8354e10>
In [52]:
a=np.linspace(-3,3,100)
b=np.linspace(-3,3,100)
In [53]:
Z=X+Y*1j
In [54]:
Z=((z**2-1)*(z-2-1j)**2)/(z**2+2+2*1j)
In [55]:
In [55]:
Z
Out[55]:
array([[-1.75 -0.25 j, -1.7188952 -0.26004172j,
-1.68624512-0.26993149j, ..., -0.42249939+0.18398836j,
-0.43645382+0.16738821j, -0.45 +0.15 j],
[-1.74070703-0.21973352j, -1.70968545-0.22821098j,
-1.67716829-0.23662446j, ..., -0.40648628+0.17023477j,
-0.4196594 +0.15402316j, -0.43243712+0.13704975j],
[-1.73299767-0.18948197j, -1.7019714 -0.19644411j,
-1.66949848-0.20343091j, ..., -0.39084214+0.15725526j,
-0.40326055+0.14141996j, -0.41529545+0.12484884j],
...,
[ 8.74369009-0.59263618j, 8.41707486-0.61180853j,
8.10421132-0.63475013j, ..., -0.6607306 -0.29299351j,
-0.6725305 -0.26094188j, -0.6834313 -0.22866642j],
[ 8.75362427-0.92394673j, 8.43152005-0.92943695j,
8.12237155-0.93934888j, ..., -0.69312093-0.3053591 j,
-0.7051459 -0.27240267j, -0.7162649 -0.23922687j],
[ 8.75 -1.25 j, 8.43301071-1.2426607 j,
8.12817394-1.24029336j, ..., -0.72642184-0.31795088j,
-0.73866723-0.28408282j, -0.75 -0.25 j]])
In [56]:
X,Y
Out[56]:
(array([[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
...,
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ]]),
array([[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0.02020202, 0.02020202, 0.02020202, ..., 0.02020202, 0.02020202,
0.02020202],
[0.04040404, 0.04040404, 0.04040404, ..., 0.04040404, 0.04040404,
0.04040404],
...,
[1.95959596, 1.95959596, 1.95959596, ..., 1.95959596, 1.95959596,
1.95959596],
[1.97979798, 1.97979798, 1.97979798, ..., 1.97979798, 1.97979798,
1.97979798],
[2. , 2. , 2. , ..., 2. , 2. ,
2. ]]))
In [57]:
plt.contour(X,Y,Z)
Out[57]:
<matplotlib.contour.QuadContourSet at 0x1cfb84c2f98>
In [58]:
plt.contour(X,Y,Z.real)
plt.contour(X,Y,Z.imag)
Out[58]:
<matplotlib.contour.QuadContourSet at 0x1cfb84410f0>
In [60]:
plt.contourf(X,Y,Z.imag)
Out[60]:
<matplotlib.contour.QuadContourSet at 0x1cfb95ee828>
In [61]:
a=np.linspace(2,3,60)
a=np.linspace(2,3,60)
In [62]:
c=X+Y*1j
In [81]:
Z=(1+1j)*(c)+(1-1j)*np.conj(c)
In [82]:
Z
Out[82]:
array([[ 0. +0.j, 0.04040404+0.j, 0.08080808+0.j, ...,
3.91919192+0.j, 3.95959596+0.j, 4. +0.j],
[-0.04040404+0.j, 0. +0.j, 0.04040404+0.j, ...,
3.87878788+0.j, 3.91919192+0.j, 3.95959596+0.j],
[-0.08080808+0.j, -0.04040404+0.j, 0. +0.j, ...,
3.83838384+0.j, 3.87878788+0.j, 3.91919192+0.j],
...,
[-3.91919192+0.j, -3.87878788+0.j, -3.83838384+0.j, ...,
0. +0.j, 0.04040404+0.j, 0.08080808+0.j],
[-3.95959596+0.j, -3.91919192+0.j, -3.87878788+0.j, ...,
-0.04040404+0.j, 0. +0.j, 0.04040404+0.j],
[-4. +0.j, -3.95959596+0.j, -3.91919192+0.j, ...,
-0.08080808+0.j, -0.04040404+0.j, 0. +0.j]])
In [83]:
X,Y
Out[83]:
(array([[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
...,
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ]]),
array([[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0.02020202, 0.02020202, 0.02020202, ..., 0.02020202, 0.02020202,
0.02020202],
[0.04040404, 0.04040404, 0.04040404, ..., 0.04040404, 0.04040404,
0.04040404],
...,
[1.95959596, 1.95959596, 1.95959596, ..., 1.95959596, 1.95959596,
1.95959596],
[1.97979798, 1.97979798, 1.97979798, ..., 1.97979798, 1.97979798,
1.97979798],
[2. , 2. , 2. , ..., 2. , 2. ,
2. ]]))
In [84]:
plt.contourf(X,Y,Z)
Out[84]:
<matplotlib.contour.QuadContourSet at 0x1cfb9a300b8>
In [85]:
plt.contourf(X,Y,z.real)
Out[85]:
<matplotlib.contour.QuadContourSet at 0x1cfb99fb550>
In [86]:
plt.contourf(X,Y,Z.imag)
Out[86]:
<matplotlib.contour.QuadContourSet at 0x1cfb9b023c8>
In [87]:
a=np.linspace(1,2,100)
b=np.linspace(1,2,100)
In [88]:
c=X+Y*1j
In [90]:
z=c*np.conj(c)
In [92]:
Z
Out[92]:
array([[ 0. +0.j, 0.04040404+0.j, 0.08080808+0.j, ...,
3.91919192+0.j, 3.95959596+0.j, 4. +0.j],
[-0.04040404+0.j, 0. +0.j, 0.04040404+0.j, ...,
3.87878788+0.j, 3.91919192+0.j, 3.95959596+0.j],
[-0.08080808+0.j, -0.04040404+0.j, 0. +0.j, ...,
3.83838384+0.j, 3.87878788+0.j, 3.91919192+0.j],
...,
[-3.91919192+0.j, -3.87878788+0.j, -3.83838384+0.j, ...,
0. +0.j, 0.04040404+0.j, 0.08080808+0.j],
[-3.95959596+0.j, -3.91919192+0.j, -3.87878788+0.j, ...,
-0.04040404+0.j, 0. +0.j, 0.04040404+0.j],
[-4. +0.j, -3.95959596+0.j, -3.91919192+0.j, ...,
-0.08080808+0.j, -0.04040404+0.j, 0. +0.j]])
In [93]:
X,Y
Out[93]:
(array([[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
...,
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ],
[0. , 0.02020202, 0.04040404, ..., 1.95959596, 1.97979798,
2. ]]),
array([[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0.02020202, 0.02020202, 0.02020202, ..., 0.02020202, 0.02020202,
0.02020202],
[0.04040404, 0.04040404, 0.04040404, ..., 0.04040404, 0.04040404,
0.04040404],
...,
[1.95959596, 1.95959596, 1.95959596, ..., 1.95959596, 1.95959596,
1.95959596],
[1.97979798, 1.97979798, 1.97979798, ..., 1.97979798, 1.97979798,
1.97979798],
[2. , 2. , 2. , ..., 2. , 2. ,
2. ]]))
In [96]:
plt.contour(X,Y,Z)
Out[96]:
<matplotlib.contour.QuadContourSet at 0x1cfbacb50b8>
In [95]:
plt.contour(X,Y,z.real)
Out[95]:
<matplotlib.contour.QuadContourSet at 0x1cfb9c6f518>
In [97]:
plt.contour(X,Y,Z.imag)
Out[97]:
<matplotlib.contour.QuadContourSet at 0x1cfbad1dc88>
In [98]:
a=np.linspace(3,4,100)
a=np.linspace(3,4,100)
In [99]:
c=X+Y*1j
In [105]:
Z=c*np.conj(c)+(1+1j)*c+np.conj((1+1j)*c)+2
In [106]:
plt.contour(X,Y,Z)
Out[106]:
<matplotlib.contour.QuadContourSet at 0x1cfbaf00e10>
In [107]:
plt.contour(X,Y,Z.real)
Out[107]:
<matplotlib.contour.QuadContourSet at 0x1cfbaf76710>
In [108]:
plt.contour(X,Y,Z.imag)
Out[108]:
<matplotlib.contour.QuadContourSet at 0x1cfbafd92b0>
conclusion:the solution is found and the graph is plotted
lab 2
aim:to find the inverse,determinant of the matrix and plot the graph
In [2]:
import numpy as np
In [6]:
x2d=np.array((100,200,300))
In [9]:
x2d=np.array((111,222,333))
In [11]:
x2d=np.array((123,456,789))
In [14]:
print(x2d.shape)
print(x2d.dtype)
print(x2d.size)
print(x2d.itemsize)
print(x2d.ndim)
print(x2d.data)
(3,)
int32
3
4
1
<memory at 0x000001F9A0830108>
In [16]:
x=np.array([1,12,25,8,15,35,50,2,10])
print(x[3:7])
print(x[1:9:2])
print(x[0:9:3])
[ 8 15 35 50]
[12 8 35 2]
[ 1 8 50]
In [25]:
import numpy as np
In [29]:
x2d=np.array(((100,200,300),(111,222,333),(123,456,789),(125,457,791),(127,459,773),(129,461,795)))
In [30]:
print (x2d[0:4,0:3])
print(x2d[0:4:2,0:3:2])
[[100 200 300]
[111 222 333]
[123 456 789]
[125 457 791]]
[[100 300]
[123 789]]
In [32]:
x2d=np.array(((100,200,300),(111,222,333),(123,456,789),(125,457,791),(127,459,773),(129,461,795)))
In [33]:
x=np.array([1,12,25,815,35,50,7,2])
In [44]:
for i in x:
print(i)
for row in x2d:
print (row)
1
12
25
815
35
50
7
2
[100 200 300]
[111 222 333]
[123 456 789]
[125 457 791]
[127 459 773]
[129 461 795]
In [1]:
import plotly
In [2]:
import plotly.plotly as py
In [3]:
import plotly.graph_objs as go
In [5]:
from plotly.tools import FigureFactory as FF
In [6]:
import numpy as np
In [7]:
import pandas as pd
In [8]:
import scipy
In [25]:
matrix1=np.matrix([[1,2],[3,1]])
matrix2=np.matrix([[3,0],[0,4]])
matrix_sum = matrix1 + matrix2
colorscale=[[0,'#EAEFC4'],[1,'#9BDF46']]
font=[ '#000000','000000']
table=FF.create_annotated_heatmap(matrix_sum.tolist(),colorscale=colorscale,font_colors=font)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-25-88cdb3c93462> in <module>()
4 colorscale=[[0,'#EAEFC4'],[1,'#9BDF46']]
5 font=[ '#000000','000000']
----> 6 table=FF.create_annotated_heatmap(matrix_sum,to.list(),colorscale=colorscale,font_colors=font)
In [28]:
matrix1 = np.matrix(
[[0, 4],
[2, 0]]
)
matrix2 = np.matrix(
[[-1, 2],
[1, -2]]
)
C:\Users\YAMUNA.A\Anaconda3\lib\site-packages\plotly\tools.py:1545: UserWarning:
High five! You successfully sent some data to your account on plotly. View your plot in your browser at
https://plot.ly/~yamuna.a/0 or inside your plot.ly account where it is named 'matrix-sum'
Out[28]:
In [27]:
import plotly
plotly.tools.set_credentials_file(username='yamuna.a',api_key='lvrrOWMSYhkDYRb1F5uu')
conclusion:the inverse and determinant of matix and hence the graph is plotted
LAB 3
aim :to study the Transpose and Upper or Lower Triangular parts using python
In [2]:
import numpy as np
In [4]:
A =([1, 2, 3],[ 2 ,4 ,6])
In [5]:
np.transpose(A)
Out[5]:
array([[1, 2],
[2, 4],
[3, 6]])
In [6]:
B =([4 ,-1, 9],[ 1, 0, 9],[0, 0, -5])
In [7]:
np.transpose(B)
Out[7]:
array([[ 4, 1, 0],
[-1, 0, 0],
[ 9, 9, -5]])
In [9]:
A =([43, 67, 89, 10, 100],[ 230, 126, 12, 0, 1],[67, 25, 46, 11, -1], [41, 4, 2, 2, 1], [1, 1, 1, 1, 1]
)
In [10]:
np.triu(A)
Out[10]:
array([[ 43, 67, 89, 10, 100],
[ 0, 126, 12, 0, 1],
[ 0, 0, 46, 11, -1],
[ 0, 0, 0, 2, 1],
[ 0, 0, 0, 0, 1]])
In [11]:
A = ([21, -32, 71],[11, 26, 81], [-21, 61, -11])
In [13]:
np.triu(A)
Out[13]:
array([[ 21, -32, 71],
[ 0, 26, 81],
[ 0, 0, -11]])
In [14]:
A = ([43, 67, 89, 10, 100], [230, 126, 12, 0, 1],[67, 25, 46, 11, -1], [41, 4, 2, 2, 1],[1, 1, 1, 1, 1]
)
In [15]:
np.tril(A)
Out[15]:
array([[ 43, 0, 0, 0, 0],
[230, 126, 0, 0, 0],
[ 67, 25, 46, 0, 0],
[ 41, 4, 2, 2, 0],
[ 1, 1, 1, 1, 1]])
In [16]:
In [17]:
np.tril(A)
Out[17]:
array([[ 21, 0, 0],
[ 11, 26, 0],
[-21, 61, -11]])
conclusion:using the python code the upprer and lower triangle is found
lab 4
aim:to sove linear equation system using python
In [11]:
import numpy as np
x + y = 35; 2x + 4y = 94
In [13]:
A=np.matrix([[1,1],[2,4]])
B=np.matrix([[35],[94]])
np.linalg.solve(A,B)
Out[13]:
matrix([[23.],
[12.]])
3x + y = 9; x + 2y = 83x + y = 9; x + 2y = 8
In [15]:
A=np.matrix([[3,1],[1,2]])
B=np.matrix([[9],[8]])
np.linalg.solve(A,B)
Out[15]:
matrix([[2.],
[3.]])
4x + 3y = -2; 8x - 2y = 12
In [17]:
A=np.matrix([[4,3],[8,-2]])
B=np.matrix([[-2],[12]])
np.linalg.solve(A,B)
Out[17]:
matrix([[ 1.],
[-2.]])
In [18]:
A=np.matrix([[3,2],[7,1]])
B=np.matrix([[16],[19]])
np.linalg.solve(A,B)
Out[18]:
matrix([[2.],
[5.]])
In [19]:
A=np.matrix([[3,4],[2,-1]])
B=np.matrix([[5],[7]])
np.linalg.solve(A,B)
Out[19]:
matrix([[ 3.],
[-1.]])
In [21]:
A=np.matrix([[1,-2,3],[2,1,1],[3,2,-2]])
B=np.matrix([[7],[7],[-10]])
np.linalg.solve(A,B)
Out[21]:
matrix([[-2.4],
[ 5.2],
[ 6.6]])
In [23]:
A=np.matrix([[2,-4,5],[4,-1,0],[-2,2,-3]])
B=np.matrix([[-33],[-5],[19]])
np.linalg.solve(A,B)
Out[23]:
matrix([[-0.5],
[ 3. ],
[-4. ]])
In [25]:
A=np.matrix([[4,-3,1],[2,1,3],[-1,2,-5]])
B=np.matrix([[-10],[0],[17]])
np.linalg.solve(A,B)
Out[25]:
matrix([[ 1.],
[ 4.],
[-2.]])
In [26]:
A=np.matrix([[1,2,-1],[2,1,1],[1,2,1]])
B=np.matrix([[4],[-2],[2]])
np.linalg.solve(A,B)
Out[26]:
matrix([[-1.66666667],
[ 2.33333333],
[-1. ]])
x + y + z = 2; 6x - 4y + 5z = 31; 5x + 2y + 2z = 13
In [28]:
A=np.matrix([[1,1,1],[6,-4,5],[5,2,2]])
B=np.matrix([[2],[31],[13]])
np.linalg.solve(A,B)
Out[28]:
Out[28]:
matrix([[ 3.],
[-2.],
[ 1.]])
In [20]:
import numpy as n
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as p
f[x,y]=2277 / (1 + x x+ y y)/16)
In [26]:
x = n.linspace(-3,3,256)
y = n.linspace(-3,3,256)
X,Y = n.meshgrid(x,y)
Z = 2277/(1+(X**2+Y**2)/16)
F = p.figure()
Ax = F.gca(projection='3d')
Ax.plot_surface(X,Y,Z,cmap=cm.gray)
p.show()
1. u = x + cos(4*x) + 3;
v = sin(4x) - sin(2y);
w = -z;
In [27]:
x = n.linspace(-3,3,256)
y = n.linspace(-3,3,256)
X,Y = n.meshgrid(x,y)
Z = 3*X**2 + 4*Y**2
F = p.figure()
Ax = F.gca(projection='3d')
Ax.plot_surface(X,Y,Z,cmap=cm.gray)
p.show()
In [28]:
F = p.figure()
Ax = F.gca(projection='3d')
x = n.arange(-0.8,1,0.2)
y = n.arange(-0.8,1,0.2)
z = n.arange(-0.8,1,0.8)
X,Y,Z = n.meshgrid(x,y,z)
u = X + n.cos(4*X) + 3
v = n.sin(4*X) - n.sin(2*Y)
w = -Z
Ax.quiver(X,Y,Z,u,v,w,length=0.1)
p.show()
conclusion:the scalar and vector fields are plotted for the given problem
lab 6
Expotional growth
In [ ]:
In [1]:
import numpy as np
import math
from sympy import *
In [2]:
t,k=Symbol('t'),Symbol('k')
p=Function('p')('t')
diffeq=Eq(p.diff(t)-k*p,0)
sol=dsolve(diffeq)
print(solve)
In [4]:
from sympy.interactive import printing
printing.init_printing (use_latex=True)
In [5]:
display(sol)
In [6]:
p0=Symbol("p0")
constants=solve([sol.subs([(p,p0),(t,t)]),sol.subs([(p,3/2*p0),(t,t+1)])])
In [7]:
sol=sol.subs(k,constants[1][k])
In [8]:
sol
Out[8]:
In [10]:
c1=solve(sol.subs([(p,p0),(t,0)]))
In [11]:
c1
Out[11]:
In [12]:
sol=sol.subs(c1[0])
In [13]:
sol
Out[13]:
In [16]:
solve([sol.subs(p,3*p0)],t)
Out[16]:
In [19]:
from scipy .integrate import odeint
import matplotlib.pyplot as plt
In [20]:
def expre(y,x):
return math.e**(constants[1][k]*x)
In [21]:
x=np.linspace(0,10,1000)
p0=0
y=odeint (expre,p0,x)
In [22]:
plt.plot (x,y)
plt.show()
CONCLUSION
In [23]:
the time necessary for the bacteria to triple t=2.70951129135146 the following is plotted to show the e
the time necessary for the bacteria to triple t=2.70951129135146 the following is plotted to show the e
xponential growth
Compound interest
aim:to find the solution by continous componding using python
In [1]:
import numpy as np
In [1]:
In [4]:
In [5]:
def exp(A,t):
i=0,12
return A*i
def exp(A,t):
i=0,12
return A*i
simple interest
In [14]:
def INT (p,t,r):
i=p*t*r/100
return i
In [16]:
INT (100000,5,12)
Out[16]:
60000.0
In [17]:
In [18]:
amt(10000,5,12)
Out[18]:
16000.0
In [21]:
def RATE (A,p,t):
def RATE (A,p,t):
r=(1-(p/A))*100/t
return r
In [24]:
print(RATE(10000,5,6000),'%')
0.016658333333333334 %
In [25]:
def sitimecalc(A,p,t):
return (1-(p/A))*100/t
In [26]:
def sitimecalc(A,t,r):
return (1-(p/A))*100/r
In [27]:
def principlecalc(A,t,r):
return a*(1+(r*t/100))**(-1)
continous compound
In [32]:
def cont(A0,t,n,r):
t=numpy.linspace(0,T,n*T)
global i
i=r/(T*n)
y=odinet(exp,A0,t)
return float(y[-1])
In [35]:
import numpy
import matplotlib.pyplot as plt
A0=1000
T=100
monthly=12
annually=1
daily=365
r=10
tM=numpy.linspace(0,T,monthly*T)
tA=numpy.linspace(0,T,annually*T)
tD=numpy.linspace(0,T,daily*T)
In [38]:
yA=Amount(A0,tA,r,annually)
yM=Amount(A0,tM,r,monthly)
yD=Amount(A0,tD,r,daily)
In [39]:
plt.plot(tM,yM,label='Monthlly')
plt.plot(tA,yA,label='Annually')
plt.plot(tD,yD,label='daily')
plt.title("compound interest")
plt.xlabel("Time")
plt.xlabel("Time")
plt.label("amount")
plt.legend()
plt.show()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-39-d8b8e82111eb> in <module>()
4 plt.title("compound interest")
5 plt.xlabel("Time")
----> 6 plt.label("amount")
7 plt.legend()
8 plt.show()
In [27]:
import numpy as np
from scipy .integrate import odeint
import matplotlib.pyplot as plt
In [28]:
def expr(X,t):
umax,K=1,50
return X*umax*(1-X/K)
In [29]:
t=np.linspace(-10,10,100)
X0=10
X=odeint(expr,X0,t)
In [30]:
plt.plot(t,X)
plt.show()