필터 지우기
필터 지우기

Find and draw max. and min values of function.

조회 수: 2 (최근 30일)
Ali Kareem
Ali Kareem 2015년 12월 10일
댓글: Ali Kareem 2015년 12월 10일
Hi,
I am trying to find max. and min values for below function and draw it but I got wrong results. I do not know why?
for i=1:30
x(i)=-16+i;
y(i) = [(x.^3/7)+(x/15)+(1/35)]/[(x.^2/44)+((x)/107)+(1/25)];
plot(x,y)
end
indexmin = find(min(y) == y);
xmin = x(indexmin);
ymin = y(indexmin);
indexmax = find(max(y) == y);
xmax = x(indexmax);
ymax = y(indexmax);
strmin = ['Minimum = ',num2str(ymin)];
text(xmin,ymin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(ymax)];
text(xmax,ymax,strmax,'HorizontalAlignment','right');

답변 (1개)

Walter Roberson
Walter Roberson 2015년 12월 10일
y(i) = ((x(i).^3/7)+(x(i)/15)+(1/35)) / ((x(i).^2/44)+((x(i))/107)+(1/25));
Using [] would have worked but it is not a good idea to use [] to indicate precedence, as [] is the list building operator.
Your main problem was that you were using all of x in every calculation of y.
  댓글 수: 1
Ali Kareem
Ali Kareem 2015년 12월 10일
Hello,
Thank you so much for your reply. I got the correct result for min. but I still not get the correct answer for Max.
In addition, the code show only value of Max or Min for Y-coordinate and did not show the X-coordinate for Max. and Min.
Thanks again

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by