Print certain values from an array with a condition

조회 수: 13 (최근 30일)
Rita Akonobi
Rita Akonobi 2020년 9월 28일
댓글: Rita Akonobi 2020년 9월 28일
Hi all Please I need help to complete this assignment.I have a function f(x)=x^2*exp(-x) and would like to print f(min) and the corresponding x tha gave that value. Please look at what I have done so far and help me identify why it't not printing
x=[0:0.07:5];
y=(x).^2.*exp(-x);
if y == min(y)
disp('min value of y =', num2str (y));
disp('x value for min y=', mum2str(x));
end

채택된 답변

madhan ravi
madhan ravi 2020년 9월 28일
ix = find(y == min(y));
fprintf('min value of y = %d\n', y(ix))
fprintf('x value for min y = %d\n', x(ix))
  댓글 수: 3
madhan ravi
madhan ravi 2020년 9월 28일
Replace it with whatever you want.
Rita Akonobi
Rita Akonobi 2020년 9월 28일
ok thank you

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by