Problem 45396. Design a tubesheet for shell-and-tube heat exchangers

1 view (last 30 days)
% calculated th relationship between number of complete suqares and number of
% total squares using the area of the circle
function y = tubesheet(D)
% SquaresTotal = SquaresComplete*k + constant
k = 16*pi/44
c = 25*pi - 60*k
SqrsTotal = pi * (D/2)^2
SqrsComplete = (SqrsTotal - c)/k
y = floor(SqrsComplete)
end
Hello I am stuck on this problem. I tried to derive a mathematical relationship between the number of total squares and the number of full squares using the area of the circle and the squares. I used it to calculate the number of holes but it only worked on 3 tests conditions out of 108. Does anyone have any ideas on how else l might aprroach this question?
**I think one major problem is that l assumed a linear relationship between the total number squares inside the circle and the number of full squares inside the circle.

Answers (1)

John D'Errico
John D'Errico on 22 May 2021
Edited: John D'Errico on 22 May 2021
I won't do your homework for you, and you clearly have been asked to think about this, not to ask someone else to think about it for you.
But, no. you cannot compute the number of squares fully inside a circle merely by knowing the area of the circle. As simple a relationship as that will not happen.
You do have a simple option - just count the number of squares inside. Check each square. Is it inside or not? (Are there really that many squauares you would need to check? Of course not! Computers are fast at these things.)
So just use a loop. Actually, you don't even need an explicit loop. An implicit loop would suffice, but that would involve me writing code, telling you how to do this homework. And you are the one who needs to do the thinking here. As it is, I've probably told you more than I should by my standards, but you did make SOME effort.
Oh. what is the difference between an explicit loop and an implicit loop?
for i = 1:n
stuff
end
That is an explicit loop.
i = 1:n;
The latter is what I like to call an implicit loop, since the looping is done for you. In the latter case, operations are performed on all elements, effectively at once.
Are there direct methods? I can think of a sum that would work, but I don't know if there is an analytical expression for the summation: that starts to dive into number theoretic issues, and I just don't want to spend the mind sweat to do homework.
  1 Comment
Ntandoyakhe Tshuma
Ntandoyakhe Tshuma on 22 May 2021
Edited: Ntandoyakhe Tshuma on 22 May 2021
Thank you for the insight. I ended up figuring it out. This is not homework, its is an official matlab cody problem. I am reletively new to matlab l am just trying to challenge myself and learn more.
Attached below is the link to the original problem.
https://www.mathworks.com/matlabcentral/cody/problems/45396

Sign in to comment.

Categories

Find more on Programming 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!