Using polyfit for creating lines
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Jan
2017년 7월 17일
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.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!