Print certain values from an array with a condition

23 visualizaciones (últimos 30 días)
Rita Akonobi
Rita Akonobi el 28 de Sept. de 2020
Comentada: Rita Akonobi el 28 de Sept. de 2020
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

Respuesta aceptada

madhan ravi
madhan ravi el 28 de Sept. de 2020
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 comentarios
madhan ravi
madhan ravi el 28 de Sept. de 2020
Replace it with whatever you want.
Rita Akonobi
Rita Akonobi el 28 de Sept. de 2020
ok thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by