开发者

How to plot a graph by using looping in time?

I want to plot开发者_JAVA百科 a graph of position, velocity and acceleration of a robot joint, but I don't know how to plot it. This is my equation:

(position)
for 0<=t<=tblend,
y = theta1s+((0.5.*acc1).*(t^2));
for tblend<t<tf-tblend,
y = -195.21+(52.08.*t);
for tf-tblend<t<=tf,
y = 20-15.*((5-a)^2);

What command must I use to plot this graph? If possible, I want to display the equation of y too.


First create the grid of t values assuming a stepsize (here I picked 0.1) and the final value you mention called tf:

t = 0:0.1:tf;

Then use logical indexing to apply different functions to different regions of this grid of values:

y = ( theta1s+((0.5.*acc1).*(t^2)) ).*(0 <= t).*(t<=tblend) + ...
( -195.21+(52.08.*t)).*( tblend<t).*(t<tf-tblend) + ...
( 20-15.*((5-a)^2) ).*(tf-tblend<t).*(t<=tf);

This will apply the piecewise definitions of the function y by multiplying each difference piece by a logical that is 1 only on the region where it applies and 0 elsewhere. Then a simple

plot(t,y)

will show you the plot. For printing this functions, you'll need to format the title of your plot figure window using Matlab's native LaTeX syntax. Look up and use the LaTeX command \begin{cases} ... \end{cases} for the piecewise function stuff. You can pass most of this straight to the title() command.

For another solution, if you have the signal processing toolbox, you can just use the built-in

heaviside(t)

function. Suitably change the value of t for each left endpoint of a new segment of the piecewise function and then subtract and corresponding heaviside() term for each right endpoint of a segment. If you don't have the built-in heaviside() function, you can easily find third-party implementations at the Matlab central file exchange.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜