Info

此问题已关闭。 请重新打开它进行编辑或回答。

Finding an intersection between one data points curve and one linear curve (ax+b)

1 次查看(过去 30 天)
Hi, I work on these two curves. One is a linear data curve of expression y=ax+b, with a and b known, and the other is a curve of experimental points x_exp and y_exp. I want to find the smaller x for which this curve intersect, or at least are close enough so that we can say that they intersect. x_exp is a vector ordinated from the smaller x to the bigger x.
To do so, for each x_exp rank i from the smallest to the biggest, I calculate "delta", the gap between the coordinate y_calc (given by the linear expression ycalc=ax_exp(i)+b) and y_exp. I keep in a vector intersections all the ranks i of the gaps x(i) for which the gap delta between y_calc and y_exp is smaller than 50. However, the code doesn't work. The gap values calculated are odds, and the intersections are not the values i should find. Do anyone know where my logic/code is flawed ? Do anyone has an idea regarding how to find the intersection of these curves ? Thank you very much. Here is my code:
u=1; %used to build the intersections vector
nb_exp_value=size(x_exp);
for i=1:nb_exp_value
y_calc= a*x_exp(i)+b;
delta= abs(y_exp( i )) - abs(y_calc);
if delta < 50
intersections(u)=i
u=u+1;
end
end

回答(1 个)

Sam Cook
Sam Cook 2018-6-13
I think that the polyxpoly function is what you're looking for. It's part of the Mapping Toolbox.
X1 = -5:0.1:2;
Y1 = 3*X1 + -2; % Your linear data
X2 = -5:2;
Y2 = atan(X2) * 10; % Your experimental data
[Xi, Yi] = polyxpoly(X1, Y1, X2, Y2); % Intersection points
hold on
plot(X1, Y1);
plot(X2, Y2);
scatter(Xi, Yi, 'r*');

此问题已关闭。

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by