I am trying to write a short script that finds when an equation stops decreasing and starts increasing again, keep getting error
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Kelton McKee
el 8 de Feb. de 2020
Comentada: Rena Berman
el 14 de Mayo de 2020
%this script will find the minimum of a function/equation
clc
clear
%set variable equal to equation
t=-10:10;
%write for loop to loop our t values through our equation
for t=-10:10
%equation
y=3.*t.^2+2.*t+40;
%test to see if the next value in the loop is bigger than the last
if abs(y(t))>abs(y(t-1))
%if it is print result to command window
fprintf('The minimum value occurs at t=%0.3f',(t-1))
end
end
%this above is my script, whenever i run it i get this error
% "Array indices must be positive integers or logical values.
%Error in Lab5Script3 (line 9)
%if abs(y(t))>abs(y(t-1))"
%is there any ideas you could give me to help solve this error?
1 comentario
Respuesta aceptada
Star Strider
el 8 de Feb. de 2020
Define 'y' as an anonymous function:
y = @(t) 3.*t.^2+2.*t+40;
There are still a few problems. I will let you sort those.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!