Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
casadi-sharing-experience
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bogdan GHEORGHE
casadi-sharing-experience
Commits
adcaee83
Commit
adcaee83
authored
1 month ago
by
JB
Browse files
Options
Downloads
Patches
Plain Diff
added nlp problem
parent
89fed2bb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sec3_predefined_utilities.m
+3
-0
3 additions, 0 deletions
sec3_predefined_utilities.m
sec4_solving_NLP.m
+36
-37
36 additions, 37 deletions
sec4_solving_NLP.m
with
39 additions
and
37 deletions
sec3_predefined_utilities.m
+
3
−
0
View file @
adcaee83
clear all; close all; clc;
import casadi.*
This diff is collapsed.
Click to expand it.
sec4_solving_NLP.m
+
36
−
37
View file @
adcaee83
...
...
@@ -2,41 +2,40 @@ clear all; close all; clc;
import
casadi
.*
%% Hanging chain
N
=
15
;
m
=
40
/
N
;
% mass [kg]
D
=
70
*
N
;
% spring constant [J/m^2]
g
=
9.81
;
% gravitational constant [m/s^2]
L
=
5
/
N
;
% reference length [m]
opti
=
Opti
();
x
=
opti
.
variable
(
N
);
y
=
opti
.
variable
(
N
);
yr
=
opti
.
parameter
();
V
=
0.5
*
D
*
sum
((
sqrt
(
diff
(
x
)
.^
2
+
diff
(
y
)
.^
2
)
-
L
)
.^
2
,
1
);
V
=
V
+
g
*
sum
(
m
*
y
,
1
);
opti
.
minimize
(
V
);
opti
.
subject_to
([
x
(
1
);
y
(
1
)]
==
[
-
2
;
0
]);
opti
.
subject_to
([
x
(
N
);
y
(
N
)]
==
[
2
;
yr
]);
opti
.
set_initial
(
x
,
linspace
(
-
2
,
2
,
N
));
% Quiet
options
=
struct
;
options
.
qpsol
=
'qrqp'
;
options
.
convexify_strategy
=
'regularize'
;
options
.
print_iteration
=
false
;
options
.
print_time
=
false
;
options
.
print_status
=
false
;
options
.
print_header
=
false
;
options
.
max_iter
=
10000
;
options
.
qpsol_options
.
print_iter
=
false
;
options
.
qpsol_options
.
print_header
=
false
;
opti
.
solver
(
'sqpmethod'
,
options
);
par_nlp
=
opti
.
to_function
(
'par_nlp'
,{
yr
},{
x
(
round
(
N
/
2
))},{
'yr'
},{
'y'
});
N
=
40
;
% Number of points (chosen by us)
m
=
40
/
N
;
% Weight of each section
D
=
70
*
N
;
% Stifness coeficient
g
=
9.81
;
% gravitation acceleration
L
=
1
;
% length of the chain
% Set up optimization environment
opti_var
=
casadi
.
Opti
();
% Problem 1: Simple hanging chain
% Decision variables: positions
x
=
opti_var
.
variable
(
1
,
N
);
y
=
opti_var
.
variable
(
1
,
N
);
Vg
=
g
*
sum
(
m
*
y
);
Vs
=
0.5
*
D
*
sum
((
x
(
1
:
N
-
1
)
-
x
(
2
:
N
))
.^
2
+
(
y
(
1
:
N
-
1
)
-
y
(
2
:
N
))
.^
2
);
cost_NLP
=
Vg
+
Vs
;
opti_var
.
minimize
(
cost_NLP
);
opti_var
.
subject_to
(
x
(
1
)
==
-
2
);
opti_var
.
subject_to
(
y
(
1
)
==
1
);
opti_var
.
subject_to
(
x
(
end
)
==
2
);
opti_var
.
subject_to
(
y
(
end
)
==
1
);
opti_var
.
subject_to
(
y
>=
cos
(
0.1
*
x
)
-
0.5
);
opti_var
.
solver
(
'ipopt'
);
sol_NLP
=
opti_var
.
solve
();
% Plotting the results
figure
;
hold
on
;
plot
(
sol_NLP
.
value
(
x
),
sol_NLP
.
value
(
y
),
'-o'
);
xs
=
linspace
(
-
2
,
2
,
1000
);
plot
(
xs
,
cos
(
0.1
*
xs
)
-
0.5
,
'--r'
);
grid
on
;
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