필터 지우기
필터 지우기

Using polyfit for creating lines

조회 수: 2 (최근 30일)
Joppy
Joppy 2017년 7월 17일
댓글: Joppy 2017년 7월 18일
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개)

카테고리

Help CenterFile Exchange에서 Symbolic Solvers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by