Discretization of position and velocity

Hey all,
I need to discretize the states x (x(1) is position, x(2) is velocity) in a function called dicretize.
function s = discretize(x, par)
if 0 < x(1) < 2*pi
x(1) = x(1);
else
x(1) = mod(x(1), 2*pi);
end
s(1) = discretize(x(1), 1,par.pos_states)

 Risposta accettata

First, the condition
if 0 < x(1) < 2*pi
is not doing what it seem it does. The correct it
if 0 < x(1) && x(1) < 2*pi
Beside, why do you use the if block when you are using mod function which will automatically wrap all values in the interval [0,2*pi]. Check the following code
function s = discretize_state(x, par)
% TODO: Discretize state. Note: s(1) should be
% TODO: position, s(2) velocity.
x(1) = mod(x(1), 2*pi);
s(1) = round(x(1)/(2*pi)*(par.pos_states-1) + 1);
end

6 Commenti

There can be several way to wrap the values in this interval. What type of warping do you want? For example
y = mod(x, 2*pi)-pi; % but it will map 0 to -pi but all values will be in range [-pi,pi]
or
y = rem(x, pi); % but it will map all positive values to [0,pi] and all negative to [-pi,0]
Can you give example of how the numbers will be mapped.
Try this:
y = mod(x+pi, 2*pi)-pi;
Mm unfortunately it doesn't appear to be working, but perhaps it's because of the s(n) fucntion, which for this case has to be different. The values of x(1) will not exceed the range [−π, π], but they must be kept to this range just in case. The resulting state must be mapped also in the range [1, 31].
So in this case you want to map -pi to 1 and pi to 31?
Giulio, try this
x(2) = mod(x(2)+pi, 2*pi);
The second line should be correct.
The first one map -pi -> 0 and pi -> 2*pi and it will wrap the values according to interval [-pi, pi]. The second one map all the values in the range [-pi pi], but to use that, you will need to change
round((x(1)/(2*pi)+0.5)*(par.pos_states-1) + 1);

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Release

R2019b

Tag

Non è stata ancora inserito alcun tag.

Richiesto:

il 29 Mar 2020

Modificato:

il 4 Apr 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by