Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MBEM-2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Berkels
MBEM-2021
Commits
178acef1
Commit
178acef1
authored
5 years ago
by
Benjamin Berkels
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
69720a83
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
exp-233.ipynb
+104
-0
104 additions, 0 deletions
exp-233.ipynb
with
104 additions
and
0 deletions
exp-233.ipynb
0 → 100644
+
104
−
0
View file @
178acef1
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### IPython notebook for Example 2.3.3 from the lecture"
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"import numpy as np\n",
"from IPython.display import display, Math\n",
"\n",
"display(Math(r'A \\in \\mathbb{R}^{6 \\times 3}, A_1 \\in \\mathbb{R}^{6 \\times 4}\\text{ from Example 1.1.1}'))\n",
"delta_t = 0.15\n",
"n = 6\n",
"t = np.arange(1, n+1) * delta_t\n",
"A_1 = np.stack((t, np.exp(t), t**3, np.sin(t)), axis=1)\n",
"A = A_1[:, :-1]\n",
"print(\"A_1 = \")\n",
"print(A_1)\n",
"print(\"A = \")\n",
"print(A)"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"metadata": {},
"source": [
"display(Math(r'U^TAV=\\Sigma'))\n",
"U, sigma, VT = np.linalg.svd(A)\n",
"np.set_printoptions(precision=4, suppress=True)\n",
"print(\"sigma(A) =\", sigma)\n",
"print(\"kappa(A) = {:.1f}\".format(sigma[0]/sigma[-1]))"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"metadata": {},
"source": [
"display(Math(r'U_1^TA_1V_1=\\Sigma_1'))\n",
"U_1, sigma_1, VT_1 = np.linalg.svd(A_1)\n",
"np.set_printoptions(precision=5)\n",
"print(\"sigma(A_1) =\", sigma_1)\n",
"print(\"kappa(A_1) = {:.1e}\".format(sigma_1[0]/sigma_1[-1]))"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"metadata": {},
"source": [
"display(Math(r'\\delta y^1=10^{-2} \\begin{pmatrix} 1 & 0 & -1 & -1 & -0.5 & 1 \\end{pmatrix}^T'))\n",
"delta_y1 = 1e-2*np.array([1, 0, -1, -1, -0.5, 1])\n",
"display(Math(r'\\delta y^2=10^{-2}\\begin{pmatrix} -1 & 1 & 1 & -0.5 & -2 & 1 \\end{pmatrix}^T'))\n",
"delta_y2 = 1e-2*np.array([-1, 1, 1, -0.5, -2, 1])"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"metadata": {},
"source": [
"np.set_printoptions(precision=4)\n",
"print(\"U_1^T\\delta y^1 =\", np.matmul(U_1.T, delta_y1))\n",
"print(\"U_1^T\\delta y^2 =\", np.matmul(U_1.T, delta_y2))\n",
"display(Math(r'\\Rightarrow\\ \\delta y^1\\text{ is dominated by }u_3, \\delta y^2\\text{ dominated by }u_4'))\n"
],
"outputs": [],
"execution_count": null
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
\ No newline at end of file
%% Cell type:markdown id: tags:
### IPython notebook for Example 2.3.3 from the lecture
%% Cell type:code id: tags:
```
python
import
numpy
as
np
from
IPython.display
import
display
,
Math
display
(
Math
(
r
'
A \in \mathbb{R}^{6 \times 3}, A_1 \in \mathbb{R}^{6 \times 4}\text{ from Example 1.1.1}
'
))
delta_t
=
0.15
n
=
6
t
=
np
.
arange
(
1
,
n
+
1
)
*
delta_t
A_1
=
np
.
stack
((
t
,
np
.
exp
(
t
),
t
**
3
,
np
.
sin
(
t
)),
axis
=
1
)
A
=
A_1
[:,
:
-
1
]
print
(
"
A_1 =
"
)
print
(
A_1
)
print
(
"
A =
"
)
print
(
A
)
```
%% Cell type:code id: tags:
```
python
display
(
Math
(
r
'
U^TAV=\Sigma
'
))
U
,
sigma
,
VT
=
np
.
linalg
.
svd
(
A
)
np
.
set_printoptions
(
precision
=
4
,
suppress
=
True
)
print
(
"
sigma(A) =
"
,
sigma
)
print
(
"
kappa(A) = {:.1f}
"
.
format
(
sigma
[
0
]
/
sigma
[
-
1
]))
```
%% Cell type:code id: tags:
```
python
display
(
Math
(
r
'
U_1^TA_1V_1=\Sigma_1
'
))
U_1
,
sigma_1
,
VT_1
=
np
.
linalg
.
svd
(
A_1
)
np
.
set_printoptions
(
precision
=
5
)
print
(
"
sigma(A_1) =
"
,
sigma_1
)
print
(
"
kappa(A_1) = {:.1e}
"
.
format
(
sigma_1
[
0
]
/
sigma_1
[
-
1
]))
```
%% Cell type:code id: tags:
```
python
display
(
Math
(
r
'
\delta y^1=10^{-2} \begin{pmatrix} 1 & 0 & -1 & -1 & -0.5 & 1 \end{pmatrix}^T
'
))
delta_y1
=
1e-2
*
np
.
array
([
1
,
0
,
-
1
,
-
1
,
-
0.5
,
1
])
display
(
Math
(
r
'
\delta y^2=10^{-2}\begin{pmatrix} -1 & 1 & 1 & -0.5 & -2 & 1 \end{pmatrix}^T
'
))
delta_y2
=
1e-2
*
np
.
array
([
-
1
,
1
,
1
,
-
0.5
,
-
2
,
1
])
```
%% Cell type:code id: tags:
```
python
np
.
set_printoptions
(
precision
=
4
)
print
(
"
U_1^T\delta y^1 =
"
,
np
.
matmul
(
U_1
.
T
,
delta_y1
))
print
(
"
U_1^T\delta y^2 =
"
,
np
.
matmul
(
U_1
.
T
,
delta_y2
))
display
(
Math
(
r
'
\Rightarrow\ \delta y^1\text{ is dominated by }u_3, \delta y^2\text{ dominated by }u_4
'
))
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment