How to show values used in min() function?

If you have:
R = [0:0.01:40];
L = 800./R - 1./4*pi*R ;
cost = 30*(2*L + 4*R)+40*(pi*R) ;
min(cost)
How do I extract the values of R and L used in finding the min(cost) ?

Answers (2)

Matt J
Matt J on 6 Sep 2016
Edited: Matt J on 6 Sep 2016
mincost=min(cost);
idx=(cost==mincost);
Rmin=R(idx);
Lmin=L(idx);
[mnCost mnIdx]=min(cost);
>> sprintf('Min R,L,cost: %.2f,%.4f = %.2f',R(mnIdx),L(mnIdx),mnCost)
ans =
Min R,L,cost: 15.55,39.2340 = 6174.11

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Tags

Asked:

on 6 Sep 2016

Answered:

dpb
on 6 Sep 2016

Community Treasure Hunt

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

Start Hunting!