How to Graph with the endpoints excluded from values
Show older comments
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)
xlabel('r = radius')
ylabel('Total Cost')
legend('Total Cost for Radius')
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.
Answers (2)
ag
on 12 Mar 2025
Hi Kyle,
To ensure that the radius does not include "2" and "10," you can define "r" as follows:
r = (2.01:0.01:9.99);
Additionally, to find the minimum cost and the corresponding radius, you can use the "min" function at the end of your program as shown below:
[min_cost, min_index] = min(Cost_total);
optimal_radius = r(min_index);
Hope this helps!
r = 2:0.01:10;
r(ismember(r, [2, 10])) = [];
%cross-check
format long g
r(1)
r(end)
Categories
Find more on Graphics Performance 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!