Find minimum y value of vectors
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (3)
Star Strider
on 17 Oct 2016
Use the min function with both outputs.
I leave the rest to you.
0 Comments
Andriy Kavetsky
on 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.
0 Comments
Image Analyst
on 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.
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!