Using polyfit for creating lines

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!

 Respuesta aceptada

Jan
Jan el 17 de Jul. de 2017

0 votos

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 comentario

Joppy
Joppy el 18 de Jul. de 2017
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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 17 de Jul. de 2017

Comentada:

el 18 de Jul. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by