How to Graph with the endpoints excluded from values

5 views (last 30 days)
Kyle on 20 Sep 2022
Answered: Dyuman Joshi on 21 Sep 2022
I have a cost to radius problem involving a water tower with a cylinder bas and a hemispherical top. The problem asks to plot the total cost of building the water tower with 2<r<10, with 2 and 10 not being included, in an interval of 0.01 to account for pennies in the cost. Here is my current process:
Equations listed in the problem
% r = 2:0.01:10;
% sa_of_cylinder = 2*pi*r*h;
% volume_of_cylinder = pi*r^2*h;
% sa_of_top = 2*pi*r.^2;
% volume_of_top = (2*pi*r.^3)/3;
% Cost_Cylinder = 300*sa_of_cylinder;
% Cost_Top = 400*sa_of_top;
% V_total = 500
% Find the radius that results in the least cost
% Cost_total = Cost_Cylinder + Cost_Top;
%
% Cost_total = 300*2*pi*r*h + 400*2*pi*r^2
%
% V_total = volume_of_top + volume of Cylinder
% 500 = volume_of_top + pi*r^2*h
% h = (500 - volume_of_top)/(pi*r^2)
%
% Substitute h back into the cost total
%
% Cost_total = ((600*pi*r)*((500-volume_of_top))/(pi*r^2) + Cost_Top
r = (2:0.01:10);
volume_of_top = (2*pi*r.^3)/3;
Cost_Top = 800*pi*r.^2;
Cost_total = 600*pi*r*((500-volume_of_top)/(pi*r.^2)) + Cost_Top;
plot(r,Cost_total)
ylabel('Total Cost')
grid on
title('Cost of Building a Water Tower of Differing Radii')
According to the code, the minimum cost is associated with a radius of 2, but i dont want to have r=2 be an option. I am not even sure my graph is correct, for all i know i got it wrong. I just need someone with a greater understanding of Matlab to test the process and plot for the minimum cost and associated radius, or tell me what part of the code i got wrong.

Dyuman Joshi on 21 Sep 2022
d=0.01;
r=(2+d:d:10-d); %not including 2 and 10
vtop = (2*pi*r.^3)/3;
Cost_Top = 400*(2*pi*r.^2);
Cost_total = 600*pi*r*((500-vtop)/(pi*r.^2)) + Cost_Top;
Since for some values of r, cost is negative, which means, total volumne exceeds 500, which is not allowed. So we find the first positive minimum value.
%index
idx = find(Cost_total>=0,1)
idx = 19
%minimum cost value
minvalue = Cost_total(idx)
minvalue = 1.8283
%corresponding r
rval = r(idx)
rval = 2.1900
Your code for plot is correct.

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by