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!

采纳的回答

Jan
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.
  1 个评论
Joppy
Joppy 2017-7-18
Thanks. You mean using the line function? I can't really calculate the intersection without first defining a line. i.e., i don't know where the new end point will be before calculating that line. Also, there can be more than one intersection.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by