필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I'm having trouble writing this function can anyone help?

조회 수: 1 (최근 30일)
jose sanchez
jose sanchez 2016년 4월 11일
마감: MATLAB Answer Bot 2021년 8월 20일
Chapter 15 #5
Mathematically speaking, a critical point occurs when the derivative of a function equals zero. It is possible that a local minimum or a local maximum occurs at a critical point. A local minimum is a point where the function's value to the left and right of it are larger, and a local maximum is a point where the function's value to the left and right are smaller.
Write a function that finds the local minimum and local maximum points. Call the function findPoints. It should take in a vector of x values and a vector of y values and return two vectors:
the first vector should contain the x values where the minimum points occur
the second vector should contain the x values where the maximum points occur. You may assume that the local minimums and maximums occur at integer values. This will take care of any decimals created when using diff.
Example:
x = linspace(-5, 5, 1000); y = x.^3 -12*x; [min max] = findPoints(x, y) should return min = 2 max = -2
  댓글 수: 4
Walter Roberson
Walter Roberson 2016년 4월 11일
What is "locat" ?
Walter Roberson
Walter Roberson 2016년 4월 11일
It is firmly recommended that you never name a variable "min" or "max" as doing so interferes with using the MATLAB routines of those names, and makes it more difficult for other people to read the code.

답변 (1개)

Image Analyst
Image Analyst 2016년 4월 11일
Try
for k = 2 : length(y)-1
if y(k) > y(k-1) && y(k) > y(k+1)
% It's a local max
elseif y(k) < y(k-1) && y(k) < y(k+1)
% It's a local min
end
end
See if you can finish the rest of the code to store the index k as a max or min, and to get the x values there.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by