Find minimum y value of vectors

2 vues (au cours des 30 derniers jours)
Rebecca Scott
Rebecca Scott le 17 Oct 2016
The first part of the code I need to show the values of x and y vectors when t is between 0 and 10 for which I have the following code
for i=1:10;
t=i;
x = 5 + sqrt(t);
y= 2 + sin(2*t)/(t+1);
disp(['The Value for t is: ',num2str(t) , ' which gives us x as: ',num2str(x),' and y as ',num2str(y)])
end
The next task is to identify the minimum value Y vector (and the corresponding t and x values at that point). Im feeling pretty stumped as to how to find a minimum value? Any help appreciated

Réponses (3)

Star Strider
Star Strider le 17 Oct 2016
Use the min function with both outputs.
I leave the rest to you.

Andriy Kavetsky
Andriy Kavetsky le 17 Oct 2016
If you write for i=1:10; t=i, then you would'nt get vector because t=10, maybe you should write t(i)=i for creating an vector and y should be like y= 2 + sin(2.*t)./(t+1);.To find minimum y use [ymin,ind]=min(y); ymin-minimum value and ind its index, so display t(ind) and x(ind), they will correspond to y index.

Image Analyst
Image Analyst le 17 Oct 2016
Rebecca, since t = i, which goes from 1 to 10, t will ALWAYS be between 0 and 10 with your code - how could it not be? So you need to display ALL x and y. To find the min of a current value and a previous min value, you can do
minValue = min([minValue, currentValue]);
Adapt as needed.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by