This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collocation package, functions, point costs wip
- Loading branch information
Showing
18 changed files
with
211 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function coeff = coefficients(tau_root) | ||
d = length(tau_root)-1; % order | ||
coeff = zeros(d, d+1); | ||
for j=1:d+1 | ||
% Construct Lagrange polynomials to get the polynomial | ||
% basis at the collocation point | ||
basis = 1; | ||
for r=1:d+1 | ||
if r ~= j | ||
basis = conv(basis, [1, -tau_root(r)]); | ||
basis = basis / (tau_root(j)-tau_root(r)); | ||
end | ||
end | ||
coeff(j,:) = basis; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function [ points ] = collocationPoints( d ) | ||
if d == 2 | ||
points = [0 0.33333333333333333333333333333333, 1.0]; | ||
elseif d == 3 | ||
points = [0 0.15505102572168222296866701981344, 0.64494897427831787695140519645065, 1.0]; | ||
elseif d == 4 | ||
points = [0 0.088587959512704206321842548277345, 0.4094668644407346569380479195388, 0.7876594617608470016989485884551, 1.0]; | ||
elseif d == 5 | ||
points = [0 0.057104196114518224192124762339517, 0.27684301363812369167760607524542, 0.5835904323689168338162858162832, 0.86024013565621926247217743366491, 1.0]; | ||
else | ||
error('Only collocation order between 2 and 5 is supported.'); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function r = evalCoefficients(coeff, d, point) | ||
|
||
oclAssert(point<=1 && point >=0); | ||
|
||
r = zeros(d+1, 1); | ||
for j=1:d+1 | ||
r(j) = polyval(coeff(j,:), point); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function r = evalCoefficientsDerivative(coeff, tau_root, d) | ||
r = zeros(d+1, d+1); | ||
for k=1:d+1 | ||
pder = polyder(coeff(k,:)); | ||
for j=1:d+1 | ||
r(k,j) = polyval(pder, tau_root(j)); | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function r = evalCoefficientsIntegral(coeff, d, point) | ||
|
||
oclAssert(point<=1 && point >=0); | ||
|
||
r = zeros(d+1, 1); | ||
for k=1:d+1 | ||
% Evaluate the integral of the polynomial to get | ||
% the coefficients of the quadrature function | ||
p_int = polyint(coeff(k,:)); | ||
r(k) = polyval(p_int, point); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function x = getStateAtPoint(colloc, x0, vars, point) | ||
|
||
d = colloc.order; | ||
nx = colloc.num_x; | ||
nz = colloc.num_z; | ||
coeff = colloc.coefficients; | ||
|
||
coeff_eval_point = ocl.collocation.evalCoefficients(coeff, d, point); | ||
|
||
x = coeff_eval_point(1)*x0; | ||
|
||
for j=1:length(d) | ||
j_vars = (j-1)*(nx+nz); | ||
j_x = j_vars+1:j_vars+nx; | ||
x = x + coeff_eval_point(j+1)*vars(j_x); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function stage_time_struct = times(stage) | ||
stage_time_struct = OclStructure(); | ||
stage_time_struct.addRepeated({'states', 'integrator', 'controls'}, ... | ||
{OclMatrix([1,1]), OclMatrix([stage.integrator.nt,1]), OclMatrix([1,1])}, length(stage.H_norm)); | ||
{OclMatrix([1,1]), OclMatrix([stage.integrator.num_t,1]), OclMatrix([1,1])}, length(stage.H_norm)); | ||
stage_time_struct.add('states', OclMatrix([1,1])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
classdef Pointcost < handle | ||
|
||
properties | ||
point | ||
fh | ||
end | ||
|
||
methods | ||
|
||
function self = Pointcost(point, fh) | ||
self.point = point; | ||
self.fh = fh; | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.