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
Navayos Pratumthong
numer-60-2
Commits
11818e66
Commit
11818e66
authored
Feb 01, 2018
by
Navayos Pratumthong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ส่งการบ้าน assignment
parent
d7af15bc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
1 deletion
+86
-1
Chapter 03 Numerics and Error Analysis.ipynb.ipynb
week03/Chapter 03 Numerics and Error Analysis.ipynb.ipynb
+73
-1
assigment.py
week03/assigment.py
+0
-0
assignment.py
week03/assignment.py
+13
-0
No files found.
week03/Chapter 03 Numerics and Error Analysis.ipynb.ipynb
View file @
11818e66
...
...
@@ -235,6 +235,7 @@
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "skip"
}
...
...
@@ -289,6 +290,7 @@
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "skip"
}
...
...
@@ -319,6 +321,76 @@
"* ความรู้เพิ่มเติม: [Fixed-Point Numbers](https://en.wikibooks.org/wiki/Floating_Point/Fixed-Point_Numbers)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.5\n"
]
},
{
"data": {
"text/plain": [
"1.5"
]
},
"execution_count": 6,
"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",
"[ 2** 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": 8,
"metadata": {},
"outputs": [],
"source": [
"def value(v):\n",
" sign = -1 if v[0] == 1 else 1\n",
" return sign*sum([ v[i]*2**(4-i) for i in range(1,8) ])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-2.375\n"
]
}
],
"source": [
"v = [1, 0,0,1,0, 0,1,1]\n",
"print( value(v) )"
]
},
{
"cell_type": "markdown",
"metadata": {
...
...
@@ -472,7 +544,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.
5.2
"
"version": "3.
6.1
"
}
},
"nbformat": 4,
...
...
week03/assigment.py
deleted
100644 → 0
View file @
d7af15bc
week03/assignment.py
0 → 100644
View file @
11818e66
#1 homework
def
value
(
v
,
pos
=
4
,
neg
=
3
):
sign
=
-
1
if
v
[
0
]
==
1
else
1
return
sign
*
sum
([
v
[
i
]
*
2
**
(
pos
-
i
)
for
i
in
range
(
1
,
pos
+
neg
+
1
)])
#2 assignment
def
values
(
v
,
pos
,
neg
):
sign
=
-
1
if
int
(
v
[
0
])
==
1
else
1
return
sign
*
sum
(
int
(
v
[
i
])
*
2
**
(
pos
-
i
)
for
i
in
range
(
1
,
pos
+
neg
))
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