Question

A forus is shaped like a doughnut. If its inner radius isa and its outer radius is b, its volume and surface area are given b Matlab
0 0
Add a comment Improve this question Transcribed image text
Answer #1

% Matlab file : P4_fn_calc.m

function [V,A] = P4_fn_calc(a,b)
% Matlab function P4_fn_calc to calculate the volume and surface area
% of a torus gicen its inner radius, a and outer radius,b
  
V = (((pi.^2)./4).*((a+b).*((b-a).^2)));
A = (pi.^2).*((b.^2) - (a.^2));
end

%end of Matlab function

% Matlab file P4.m
% Matlab main script to calculate the values for Volume and Surface area
% for the values of a < b, a>b and a = b using values of a between 1 and 10.
% a < b
a = 2;
b = 4;

[V,A] = torus(a,b);
fprintf('a = %f b = %f V = %f A = %f\n',a,b,V,A);

% a > b
a = 4;
b = 2;

[V,A] = torus(a,b);
fprintf('a = %f b = %f V = %f A = %f\n',a,b,V,A);

% a = b
a = 2;
b = 2;

[V,A] = torus(a,b);
fprintf('a = %f b = %f V = %f A = %f\n',a,b,V,A);
% generate a plot of Volume and Surface Area vs inner radius
% generate 100 points between 0.25 and 4 for the inner radius
a = linspace(0.25,4,100);
b = a+2; % outer radius is 2 in greater than inner radius
% calculate volume and surface arae
[V,A] = torus(a,b);
% plot the graph
plot(a,V,'r-');
hold on;
plot(a,A,'b-');
hold off;
title('Volume and Surface Area of a Torus');
xlabel('Inner radius');
ylabel('Volume and surface Area');
legend('Volume','Surface Area');
%end of script

Output:

a = 2.000000 b = 4.000000 V = 59.217626 A = 118.435253 a = 4.000000 b = 2.000000 V = 59.217626 A = -118.435253 a = 2.000000 b

Add a comment
Know the answer?
Add Answer to:
Matlab A forus is shaped like a doughnut. If its inner radius isa and its outer...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT