function handle parameterization interval

1 view (last 30 days)
Hello everyone,
yesterday I got help from the community for my problem. I try to make a parameterized function of a straight line - radius - straight line (three segments). For simplicity I'd like to enter it in one single function handle as f(t) and adapt the parameter t with intervals. My function looks like this:
geo.x = @(t) t(t<=l_1) * 1 + geo.radius * cos(t(t>= l_1 & t<=l_2) / geo.radius + 1.5*pi) + t(t>=l_2) * cosd(geo.psi);
with l_1 = length of the first interval, l_2 first and second interval and l_3 length of the whole polyline. Due to any reason, matlab cant handle this, when I want to execute the function with the parameter (t = linspace 0,l_3) and returns the following error:
Error using +
Matrix dimensions must agree.
Error in @(t)t(t<=l_1)*1+geo>=l_1&t<=l_2)/geo.radius+1.5*pi)+t(t>=l_2)*cosd(geo.psi)
Can anyone tell me, where my mistake is located?
Thanks in advance! Georg

Accepted Answer

Mischa Kim
Mischa Kim on 25 Oct 2016
Edited: Mischa Kim on 25 Oct 2016
Georg, you could use something like
l_1 = 1;
l_2 = 2;
radius = 0.5;
psi = 0.2;
t = -1:0.01:5;
geo = @(t) [t(t<=l_1) * 1 , radius * cos(t(t> l_1 & t<l_2) / radius + 1.5*pi) , t(t>=l_2) * cosd(psi)];
plot(t,geo(t))
Note, the function is not quite the same as yours. Essentially, you break up the function into intervals which you then concatenate into one vector.
  1 Comment
Georg Söllinger
Georg Söllinger on 25 Oct 2016
Hello Mischa,
thanks for your fast answer. Well,the problem is, that I would prefer a single vector, as I would like to proceed with some other operations, where a single function without discontinuities would be preferable. E.g. I want to calculate the normal on the polyline with atan(y(t2)-y(t1))/(x(t2)-x(t1)) and an intersection point with a circle. Programming those operations would be much easier if only having a single function. Isn't there a way to achieve that?

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!