Using a non-linear value for pause

1 visualizzazione (ultimi 30 giorni)
Abdallah
Abdallah il 8 Apr 2014
Risposto: Abdallah il 8 Apr 2014
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

Risposte (3)

Walter Roberson
Walter Roberson il 8 Apr 2014
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 Commento
Abdallah
Abdallah il 8 Apr 2014
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.

Accedi per commentare.


Joseph Cheng
Joseph Cheng il 8 Apr 2014
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 Commenti
Joseph Cheng
Joseph Cheng il 8 Apr 2014
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 il 8 Apr 2014
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?

Accedi per commentare.


Abdallah
Abdallah il 8 Apr 2014
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.

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by