Using a non-linear value for pause

조회 수: 1 (최근 30일)
Abdallah
Abdallah 2014년 4월 8일
답변: Abdallah 2014년 4월 8일
I am trying to set a certain object to rotate, but the rotation is meant to be decaying with time. So I assume I will need an exponential function, that I can use in the pause command to do this. However I seem to still get linear rotation, even though my pause function is set to be exponential. Here is my code:
%%%%%I just posted the related part of the code
for trib=1:1:length(ang); %%%ang was used before
for ang=-0.1366*pi:.02:1.1366*pi;
xx=log(4-ang/4).*-10.96;
%%%%figure setting
%%%%plotting command
pause(xx);
end
end

답변 (3개)

Walter Roberson
Walter Roberson 2014년 4월 8일
Your x values are all negative. ang would have to be at least 3.819718633 * pi in order for (4-ang/4) to be as low as 1 and thus generate a negative log() to multiply by the negative 10.96 in order to generate a positive pause time.
  댓글 수: 1
Abdallah
Abdallah 2014년 4월 8일
I noticed i wrote it in the wrong way actually. It is supposed to be:
xx=log((4-ang)/4).*-10.96
but that still doesn't give me an exponential pause. I am trying to do a rotation similar to a step response, where time changes rapidly at first and gets slower later. That doesn't seem to work here for some reason.

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


Joseph Cheng
Joseph Cheng 2014년 4월 8일
Try exaggerating the the non-linearity and see if you see a bigger difference.
you can see how things are performing if you insert some debugging code
for ang=-0.1366*pi:.02:1.1366*pi;
tic,
xx=log((4-ang)/4).*-10.96;
pause(xx)
disp([toc xx]);
end
the displayed toc should be close to your xx value.
  댓글 수: 2
Joseph Cheng
Joseph Cheng 2014년 4월 8일
wouldn't it also be more practical to add a term to the angular rotation equation to vary the angular rotation over time rather than keeping the angular rotation constant but stretching time?
Abdallah
Abdallah 2014년 4월 8일
I have the first order equeation of 10.96dv/dt+v=4 .. assuming v is ang (the angle)
4 is the steady-state angle in radians
I am trying to get an equation for time.
the ODE can be converted into this form: v=4-4*exp(-t/10.96)
then I did a rearranging and I got t in this from t=ln((4-V)/4).*-10.96
in other words t=ln((4-ang)/4).*-10.96
but since it is inside in a for loop I imagine the ang should change therefore t is changing as well. Is there another way I can manage to get time in a more tidy and probably accurate way?

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


Abdallah
Abdallah 2014년 4월 8일
Ok now I am very certain of my mathematical model, but I am not sure how to deal with the loops.
My equation is in the form of:
for k=1:1:length(ang); %%ang previously defined as -0.1*pi:0.0174:1.103*pi;
for ang=-0.1*pi:0.0174:1.103*pi;
ggg=log((3.33-ang))/3.759);
t=ggg/-0.09;
figure(1); clf reset
plot whatever
pause(t);
end
end
My new equation for t has no chance of giving a negative value because I made sure angles are within boundary. However this time no rotation at all is happening. Can I please get help on this one.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by