Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Example notebooks
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Masiliunas, Dainius
Example notebooks
Commits
33ccaad3
Commit
33ccaad3
authored
2 years ago
by
Dainius
Browse files
Options
Downloads
Patches
Plain Diff
Add nonlinear equation solver example
parent
e6ddb736
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nonlinear_equation_solver.ipynb
+208
-0
208 additions, 0 deletions
nonlinear_equation_solver.ipynb
with
208 additions
and
0 deletions
nonlinear_equation_solver.ipynb
0 → 100644
+
208
−
0
View file @
33ccaad3
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "e71b93f4",
"metadata": {},
"outputs": [],
"source": [
"library(nleqslv)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "df6017b9",
"metadata": {},
"outputs": [],
"source": [
"eqs = function(x) {\n",
" a = 2* x[1] + x[2] + x[3] + x[4] - 2\n",
" b = 3* x[1] + 2*x[2] +0.5*x[3] + 0.3*x[4] - 4\n",
" d = x[1] + 2*x[2] + x[3]*x[4] - 5\n",
" e = 0.5*x[1] + 3*x[2] + x[3]+ 0.8*x[4] - 1.5\n",
" return(c(a,b,d,e))\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "5dfab7d9",
"metadata": {},
"outputs": [],
"source": [
"solution = nleqslv(c(0,0,0,0), eqs)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "aa49261b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"$x\n",
"[1] 1.196018 1.040414 -1.343332 -0.962883\n",
"\n",
"$fvec\n",
"[1] -0.8737645 0.7083522 -0.4296814 0.1056137\n",
"\n",
"$termcd\n",
"[1] 3\n",
"\n",
"$message\n",
"[1] \"No better point found (algorithm has stalled)\"\n",
"\n",
"$scalex\n",
"[1] 1 1 1 1\n",
"\n",
"$nfcnt\n",
"[1] 80\n",
"\n",
"$njcnt\n",
"[1] 6\n",
"\n",
"$iter\n",
"[1] 35\n",
"\n"
]
}
],
"source": [
"print(solution)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "8428588b",
"metadata": {},
"outputs": [],
"source": [
"solution = nleqslv(c(0,0,0,0), eqs, method=\"Newton\", global=\"gline\")"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "66631006",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"$x\n",
"[1] 1.0766247 0.5363726 -0.4786634 -0.2109586\n",
"\n",
"$fvec\n",
"[1] 1.388134e-08 -4.953707e-09 -2.749652e+00 4.138353e-09\n",
"\n",
"$termcd\n",
"[1] 3\n",
"\n",
"$message\n",
"[1] \"No better point found (algorithm has stalled)\"\n",
"\n",
"$scalex\n",
"[1] 1 1 1 1\n",
"\n",
"$nfcnt\n",
"[1] 140\n",
"\n",
"$njcnt\n",
"[1] 12\n",
"\n",
"$iter\n",
"[1] 12\n",
"\n"
]
}
],
"source": [
"print(solution)"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "aefea231",
"metadata": {},
"outputs": [],
"source": [
"solution = nleqslv(c(0,0,0,0), eqs, global=\"none\", control=list(maxit=15000))"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "52d7bb84",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"$x\n",
"[1] 1.0657401 0.4601809 0.2995803 -0.8912416\n",
"\n",
"$fvec\n",
"[1] -9.170442e-14 -8.215650e-14 -3.280896e+00 8.482104e-14\n",
"\n",
"$termcd\n",
"[1] 4\n",
"\n",
"$message\n",
"[1] \"Iteration limit exceeded\"\n",
"\n",
"$scalex\n",
"[1] 1 1 1 1\n",
"\n",
"$nfcnt\n",
"[1] 15000\n",
"\n",
"$njcnt\n",
"[1] 1\n",
"\n",
"$iter\n",
"[1] 15000\n",
"\n"
]
}
],
"source": [
"print(solution)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7d39bf1b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "4.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:code id:e71b93f4 tags:
```
R
library
(
nleqslv
)
```
%% Cell type:code id:df6017b9 tags:
```
R
eqs
=
function
(
x
)
{
a
=
2
*
x
[
1
]
+
x
[
2
]
+
x
[
3
]
+
x
[
4
]
-
2
b
=
3
*
x
[
1
]
+
2
*
x
[
2
]
+0.5
*
x
[
3
]
+
0.3
*
x
[
4
]
-
4
d
=
x
[
1
]
+
2
*
x
[
2
]
+
x
[
3
]
*
x
[
4
]
-
5
e
=
0.5
*
x
[
1
]
+
3
*
x
[
2
]
+
x
[
3
]
+
0.8
*
x
[
4
]
-
1.5
return
(
c
(
a
,
b
,
d
,
e
))
}
```
%% Cell type:code id:5dfab7d9 tags:
```
R
solution
=
nleqslv
(
c
(
0
,
0
,
0
,
0
),
eqs
)
```
%% Cell type:code id:aa49261b tags:
```
R
print
(
solution
)
```
%% Output
$x
[1] 1.196018 1.040414 -1.343332 -0.962883
$fvec
[1] -0.8737645 0.7083522 -0.4296814 0.1056137
$termcd
[1] 3
$message
[1] "No better point found (algorithm has stalled)"
$scalex
[1] 1 1 1 1
$nfcnt
[1] 80
$njcnt
[1] 6
$iter
[1] 35
%% Cell type:code id:8428588b tags:
```
R
solution
=
nleqslv
(
c
(
0
,
0
,
0
,
0
),
eqs
,
method
=
"Newton"
,
global
=
"gline"
)
```
%% Cell type:code id:66631006 tags:
```
R
print
(
solution
)
```
%% Output
$x
[1] 1.0766247 0.5363726 -0.4786634 -0.2109586
$fvec
[1] 1.388134e-08 -4.953707e-09 -2.749652e+00 4.138353e-09
$termcd
[1] 3
$message
[1] "No better point found (algorithm has stalled)"
$scalex
[1] 1 1 1 1
$nfcnt
[1] 140
$njcnt
[1] 12
$iter
[1] 12
%% Cell type:code id:aefea231 tags:
```
R
solution
=
nleqslv
(
c
(
0
,
0
,
0
,
0
),
eqs
,
global
=
"none"
,
control
=
list
(
maxit
=
15000
))
```
%% Cell type:code id:52d7bb84 tags:
```
R
print
(
solution
)
```
%% Output
$x
[1] 1.0657401 0.4601809 0.2995803 -0.8912416
$fvec
[1] -9.170442e-14 -8.215650e-14 -3.280896e+00 8.482104e-14
$termcd
[1] 4
$message
[1] "Iteration limit exceeded"
$scalex
[1] 1 1 1 1
$nfcnt
[1] 15000
$njcnt
[1] 1
$iter
[1] 15000
%% Cell type:code id:7d39bf1b tags:
```
R
```
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