Commit 5d856783 authored by Kittipong Maneewong's avatar Kittipong Maneewong

add quiz

parent 8f3cce28
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="nose" />
<item index="1" class="java.lang.String" itemvalue="coverage" />
<item index="2" class="java.lang.String" itemvalue="mock" />
<item index="3" class="java.lang.String" itemvalue="PyHamcrest" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
This diff is collapsed.
def single(v):
v+="0"*(32-len(v))
sign = -1 if v[0] == '1' else 1
e=sum([(int(v[i])*2**(8-i)) for i in range(1,9)])
x=1+sum([int(v[i])*(2**(8-i)) for i in range(9,32)])
print(sign*x*2**(e-127))
single("01101011101101010000000000000000")
single("11001100101111100010000000000000")
def double(v):
v += "0" * (64 - len(v))
v=v.replace(" ","")
sign=(-1)**int(v[0])
e=sum([int(v[i])*(2**(11-i)) for i in range(1,12)])
x=1+sum([int(v[i])*(2**(11-i)) for i in range(12,64)])
print (sign*x*2**(e-1023))
double("0 01111111111 0000000000000000000000000000000000000000000000000000")
double("11000000000000000000000000000000000000000000000000000000000000000")
double("01000000001101110000000000000000000000000000000000000000000000000")
import numpy as np
def Ab2Uc(A, b):
A=np.array(A,float)
b=np.array(b,float)
n=len(b)
for k in range(0,n-1):
for i in range(k+1,n):
if A[i,k] != 0.0:
lam=A[i,k]/A[k,k]
A[i,k]=0
A[i,k+1:n] -= lam*A[k,k+1:n]
b[i]-=lam*b[k]
print (A)
print (b)
A = [
[4, -2, 1],
[-2, 4, -2],
[1, -2, 4]
]
b = [
11,
-16,
17
]
Ab2Uc(A, b)
...@@ -6,5 +6,4 @@ M = [ ...@@ -6,5 +6,4 @@ M = [
[3, 2, 1, 2], [3, 2, 1, 2],
[5, 4, 3, 3], [5, 4, 3, 3],
[7, 3, 6, 4] [7, 3, 6, 4]
] ]
sub(M, 2, 2, 0, 1) \ No newline at end of file
\ No newline at end of file
import numpy as np
def solve(A, b):
A=np.array(A,float)
b=np.array(b,float)
n=len(b)
for k in range(0,n-1):
for i in range(k+1,n):
if (A[i,k] != 0.0) :
lam=A[i,k]/A[k,k]
A[i,k]=0
A[i,k+1:n]-=lam*A[k,k+1:n]
b[i]-=lam*b[k]
x=b.copy()
for k in range(n-1,-1,-1):
x[k]=(b[k]-np.dot(A[k,k+1:n],x[k+1:n]))/A[k,k]
print (x)
A = [
[4, -2, 1],
[-2, 4, -2],
[1, -2, 4]
]
b = [
11,
-16,
17
]
solve(A, b)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment