Using polyfit for creating lines
4 views (last 30 days)
Show older comments
Hi.
I'm working on a problem that involves the calculation of 'trajectories' over and over again. The trajectories are straight lines. Currently, i am creating these lines in the following fashion,
%Example
x(1) = x0; %Defined elsewhere
y(1) = y0; %''
m = 1; %Slope
t = [0:0.1:1];
n = length(t);
for i = 1:n
x(i) = m*t(i) + x0;
y(i) = m*t(i) + y0;
end
Then,
f = poly2sym(polyfit(x, y, 1)); %symbolic function f(t)
g = matlabFunction(f); % @(t) g
I use f when i need to test whether the function is intersecting with another function (generated by other means), and g when i need to evaluate points on the trajectory, or plot the line, e.g., plot(t, g(t))...
Is it possible to specify which values the function f is defined on?
E.g. Suppose i have two intersecting lines (generated by the above scheme), and i wish to draw a new line starting from the point of intersection. The new line can start at (x0, y0), but is it possible to have it defined only for values >= x0 (or something of this sort)?
I ask this since when draw this new line using the above method, i end up finding a root at the point where the new line is supposed to start (x0)! So either i change how new 'lines' are formed, or i change the root finding scheme. The latter is not really possible given my situation..
Thanks for any tips or advice!
0 Comments
Accepted Answer
Jan
on 17 Jul 2017
What about defining the lines by the start and end point, instead of the y=m*x+b equation? Do you need the symbolic expression for these equations? It is easy to claculate e.g. intersections numerically.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!