Find minimum y value of vectors
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Andriy Kavetsky
2016-10-17
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 个评论
Image Analyst
2016-10-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!