Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
numer-60-2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Narumon Mokpha
numer-60-2
Commits
078d4361
Commit
078d4361
authored
Feb 01, 2018
by
Narumon Mokpha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ส่งงาน
parent
8f148b2d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
1 deletion
+119
-1
Chapter 03 Numerics and Error Analysis-checkpoint.ipynb
...s/Chapter 03 Numerics and Error Analysis-checkpoint.ipynb
+0
-0
Chapter 03 Numerics and Error Analysis.ipynb
week03/Chapter 03 Numerics and Error Analysis.ipynb
+109
-1
assignment.py
week03/assignment.py
+10
-0
No files found.
week03/.ipynb_checkpoints/Chapter 03 Numerics and Error Analysis-checkpoint.ipynb
0 → 100644
View file @
078d4361
This diff is collapsed.
Click to expand it.
week03/Chapter 03 Numerics and Error Analysis.ipynb
View file @
078d4361
...
...
@@ -120,6 +120,26 @@
"> ตัวเลขที่สามารถแปลงให้เป็นเลขฐานสองได้"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'0b1010'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bin(10)"
]
},
{
"cell_type": "markdown",
"metadata": {
...
...
@@ -235,6 +255,7 @@
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "skip"
}
...
...
@@ -289,6 +310,7 @@
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "skip"
}
...
...
@@ -336,6 +358,92 @@
"$0.1 \\times 0.1 = 0.01 \\approx 0.0$ \n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.5\n"
]
},
{
"data": {
"text/plain": [
"1.5"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"v = [0 ,0,0,0,1, 1,0,0]\n",
"sign = -1 if v[0] == -1 else 1\n",
"value = v[1]*2**3\n",
"value += v[2]*2**2\n",
"value += v[3]*2**1\n",
"value += v[4]*2**0\n",
"\n",
"value += v[5]*2**(-1)\n",
"value += v[6]*2**(-2)\n",
"value += v[7]*2**(-3)\n",
"\n",
"print(sign*value)\n",
"[(i,4-i) for i in range(1,8)]\n",
"[v[i]*2**(4-i)for i in range(1,8)]\n",
"sum([v[i]*2**(4-i)for i in range(1,8)])"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.375\n"
]
}
],
"source": [
"def value(v,p,n):\n",
" sign = -1 if v[0] == 1 else 1\n",
" \n",
" return sign*sum([v[i]*2**(p-i)for i in range(1,(p+n+1))])\n",
"\n",
" \n",
"v = [0, 0,0,0,1, 0,1,1]\n",
"\n",
"print( value(v,4,3) )"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.375\n"
]
}
],
"source": [
" \n",
"v = [0, 0,0,0,1, 0,1,1]\n",
"\n",
"print( value(v,4,3) )\n"
]
},
{
"cell_type": "markdown",
"metadata": {
...
...
@@ -472,7 +580,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.
5.2
"
"version": "3.
6.1
"
}
},
"nbformat": 4,
...
...
week03/assignment.py
0 → 100644
View file @
078d4361
def
value
(
v
,
p
,
n
):
sign
=
-
1
if
v
[
0
]
==
1
else
1
return
sign
*
sum
([
v
[
i
]
*
2
**
(
p
-
i
)
for
i
in
range
(
1
,(
p
+
n
+
1
))])
v
=
[
0
,
0
,
0
,
0
,
1
,
0
,
1
,
1
]
print
(
value
(
v
,
4
,
3
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment