Program 27) Minimum Cost
Problem: The cost of operation of a unit consist of two components C1 and C2 which can be expressed as functions of a parameter p as follows:
C1 = 30 - 8p
C2 = 10 + p(square)
The parameter p ranges from 0 to 10. Determine the values of p with an accuracy of +0.1 where the cost of operation would be minimum.
Problem Analysis:
Total cost = C1 + C2 = 40 - 8p + p(square)
The cost is 40 when p = 0, and 33 when p = 1 and 60 when p = 10. The cost, therefore, decreases first and then increases. This program evaluates the cost at successive intervals of p (in steps of 0.1) and stops when the cost begins to increase. The program employs break and continue statements to exit the loop.
PROGRAM
main ( )
{
float p, cost, p1, cost1 ;
for (p = 0; p <= 10; p = p + 0.1)
{
cost = 40 - 8 * p + p * p ;
if (p == 0)
{
cost1 = cost ;
continue ;
}
if (cost >= cost1)
break ;
cost1 = cost ;
p1 = p ;
}
p = (p +p1) / 2.0;
cost = 40 - 8 * p + p * p ;
printf ("\nMINIMUM COST = %.2f AT p = %.1f\n",
cost, p) ;
}
Output: MINIMUM COST = 24.00 AT p = 4.0
No comments:
Post a Comment