필터 지우기
필터 지우기

Discretization of position and velocity

조회 수: 5 (최근 30일)
GCats
GCats 2020년 3월 29일
편집: GCats 2020년 4월 4일
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)

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 29일
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
Ameer Hamza
Ameer Hamza 2020년 3월 31일
Giulio, try this
x(2) = mod(x(2)+pi, 2*pi);
The second line should be correct.
Ameer Hamza
Ameer Hamza 2020년 3월 31일
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);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Big Data Processing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by