find the points of intersection between the two curves. set it as an array p1 = [x, y] in matlab

To find the points of intersection between two curves in MATLAB, you need to follow these steps:

  1. Define the two curves that you want to find the intersection of.
  2. Use the polyxpoly function to find the points of intersection between the two curves.
  3. Extract the x and y values of each intersection point and store them in an array.

Here's an example code snippet that demonstrates how to do this:

main.m
% Define the two curves
x1 = linspace(-5, 5, 100);
y1 = x1.^2;
x2 = linspace(-5, 5, 100);
y2 = sin(x2);

% Find the points of intersection
[xi, yi] = polyxpoly(x1, y1, x2, y2);

% Store the intersection points in an array
n = length(xi);
p1 = zeros(n, 2);
for i = 1:n
    p1(i, 1) = xi(i);
    p1(i, 2) = yi(i);
end
316 chars
17 lines

In this example, we define two curves (a parabola and a sine wave), find their intersection points using polyxpoly, and then store the points in an array p1 of size n-by-2. Each row of the array corresponds to one intersection point, with the x and y values stored in the first and second columns, respectively.

gistlibby LogSnag