Find intersection between two curves
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hello i have plot two curves and i would like to create a function so as to find the intersections between the two curves
Here is my code :
x=-100*pi:pi/32:100*pi;
y1=exp(x);
y2=sin(x);
figure(1)
plot(y1,'b');hold on
plot(y2,'g');
hold off
grid
채택된 답변
The intersection is the location, where both functions have the same value. Then their difference is 0.
You can use fzero with the function: @(x) exp(x) - sin(x).
댓글 수: 8
Hello sir , thank you for the detailed explanations i did try but did not got the intersections
Please post the code you have tried and explain, what "did not get" mean.
What is a meaningul range for searching for intersections? exp(x) is growing very fast, while sin(x) lives inside [-1, +1]. So maybe:
x = linspace(-4*pi, pi, 1000);
y1 = exp(x);
y2 = sin(x);
figure
plot(x, y1, 'b', x, y2, 'g');

Then you could start the search for the zeros of @(x) exp(x) - sin(x) at e.g. -3 - these are the two inputs for fzero().
x = linspace(-4*pi, pi, 1000);
y1 = exp(x);
y2 = sin(x);
figure
plot(x, y1, 'b', x, y2, 'g');
x1=y1 -y2;
fzero = (x1,-3);
i did try it like this,but im getting some errors
Please post the error message, if you mention an error.
fzero is a function. You have to provide a function as 1st input:
fzero(@(x) exp(x) - sin(x), -3)
@Star Strider: What a pitty that you have deleted your answer. It was a valuable addition to my answer: You have considered the situation, that the input data are provided as vectors, while I suggested a method, when they are functions.
If somebody searchs in the forum for "intersection between two curves", your answer might have been more suiting then my one.
Your answers are too valuable to be deleted. They are useful and do not impede the readers.
I thought of unselecting my answer and accepting yours to keep it in the forum. But this cannot be a general strategy.
Hi guys! I need to find the intersection between two curves but one of them is given as vectors (experimental data). Could you please help me with that? Thank you in advance!
Is interpolating the measurement data by a spline curve, taking the difference of the two so created curves and searching for a zero of this difference function an option ?
% Artificial measurement data
x = 0:0.1:2;
fi_measurement = x.^2;
% Second curve
f = @(x) x;
% Fit measurement data by spline curve
f_measurement = @(xq) interp1(x,fi_measurement,xq,'spline');
% Find intersection(s) between spline curve and second curve
sol1 = fzero(@(x)f(x)-f_measurement(x),0.5)
sol1 = -1.0469e-22
sol2 = fzero(@(x)f(x)-f_measurement(x),1.5)
sol2 = 1
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
