How can i use intersect function correctly ?
Show older comments
I tried the following code to use intersect function available in Matlab f=@(x)1+cos(x); g=@(x)sin(x); x=-8:.01:8; A = intersect(f(x),g(x)) % this returns empty plot(x,f(x),x,g(x)); but the intersect function returns empty, even though it appears that there are common values for both functions defined over same x-interval. Can anyone clarify this ?
1 Comment
"Can anyone clarify this ?"
The two arrays do not share any data points.
"How can i use intersect function correctly ?"
To do what exactly?:
- return common data points from two sets of data (just as the function is documented)
- find intersections of two functions (perhaps what you really want to achieve)
Accepted Answer
More Answers (1)
There are no overlapping points:
f = @(x) 1 + cos(x);
g = @(x) sin(x);
x = 1.54:.01:1.6;
plot(x, f(x), 'r.', x, g(x), 'b.');
The same matters the other points, where the graphs intersect, but not at any of the fixed raster points x=-8:.01:8. A real intersection:
format long g
xi = fzero(@(x) f(x) - g(x), [1.54, 1.6])
A symbolic solution of the intersections:
syms x
eq = 1 + cos(x) - sin(x) == 0
solve(eq)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
