How can i use intersect function correctly ?
이전 댓글 표시
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
"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)
채택된 답변
추가 답변 (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)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

