Вы находитесь на странице: 1из 24

Laboratory Exercise No.

3
SIMPLE SOLID MENSURATION MATLAB PROGRAM

1. Objective:
The activity aims to create matlab program that will ask the user to choose between the two types of
figures in solid mensuration and output the area, perimeter/circumference, volume or surface area of a
certain figure.

2. Intended Learning Outcomes (ILOs):


The students shall be able to:
2.1 create matlab programs that will determine the area and perimeter of five(5) plane figures
2.2 create matlab programs that will determine the volume and surface area of five(5) solid figures
2.3 use switchcase break in creating matlab program for a simple solid mensuration problem-
solving situation.

3. Discussion :
Solid Mensuration is a branch of mathematics that deals with the area and perimeter/circumference of
plane figures and volume and surface area of solid figures.

4. Resources:
Matlab

5. Procedure:
1. Using the matlab editor , choose File/New/ Blank m-file , type the following:
clc;
disp('Area of the Rectangle');
length=input('Enter the length of the rectangle: ');
width=input('Enter the width of the rectangle :');
area=length*width;
fprintf('The area of the rectangle is %0.2f. ',area );

2. Save the file as areaRectangle. Run the program and record the results.
3. Create m-file for the area of the square, right triangle, oblique triangle, circle and ellipse.
4. Create m-file for the perimeter of square, rectangle, right triangle, oblique triangle, circle and
ellipse. For circle, use circumference instead of perimeter.
5. Create m-file for the volume of cone, sphere, rectangular parallelepiped, right circular cylinder and
cube.
6. Create m-file for the surface area of cone, sphere, rectangular parallelepiped, right circular cylinder
and cube.
7. Using the matlab editor, choose File/New/Blank m-file, type the following:
clc;
disp('Area and Perimeter of the Rectangle');
choose=input('\n 1. Area of the Rectangle \n 2. Perimeter of the Rectangle \n Choose 1 or 2: ');
switch(choose)
case 1;
length=input('Enter the length of the rectangle: ');
width=input('Enter the width of the rectangle :');
area=length*width;
fprintf('The area of the rectangle is %0.2f. ',area );
break;
case 2;
length=input('Enter the length of the rectangle: ');
width=input('Enter the width of the rectangle :');
perimeter= 2*length + 2*width;
fprintf('The perimeter of the rectangle is %0.2f. ',perimeter );
break;
end
8. Create a matlab program that will ask the user to choose between plane figures and solid figures.
If the user will choose plane figures, he will then be ask to choose among the five (5) plane figures
as mentioned in Procedure No. 4. After choosing any of the five (5) plane figures, he will then be
ask to choose between area and perimeter. If the user will choose solid figures, he will then be ask
to choose among the five (5) solid figures as mentioned in Procedure No. 5. After choosing any of
the five (5) solid figures, he will then be ask to choose between volume and surface area.
Necessary inputs are needed and the output will be any of the area or perimeter of any of the five
(5) plane figures and any of the volume and surface area of any of the five (5) solid figures.

Course: CHE 508 Laboratory Exercise No.: 3


Group No.: Section: CH51FC1
Group Members: Date Performed: JUNE 28, 2017
CUESTA, ALWYN WREN C Date Submitted: JULY 5, 2017
Instructor:
ENGR. CRISPULO MARANAN
6. Data and Results:

PROCEDURE NO. MATLAB OUTPUT

1 areaRectangle.m
clc;

disp('Area of the Rectangle');

length=input('Enter the length of the rectangle: ');

width=input('Enter the width of the rectangle :');

area=length*width;

fprintf('The area of the rectangle is %0.2f. ',area );

2 Sample Output on MATLAB

Area of the Rectangle

Enter the length of the rectangle: 2

Enter the width of the rectangle :5

The area of the rectangle is 10.00. >>

3 areaSquare.m
clc;

disp('Area of Square');

s=input('Enter the length of the square: ');

area=s^2;

fprintf('The area of the square is %0.2f. ',area );

Sample Output on MATLAB


Area of Square

Enter the length of the square: 6

The area of the rectangle is 36.00. >>

areaRightTriangle.m
clc;

disp('Area of Right Triangle');

h=input('Enter the height of the triangle:');

b=input('Enter the base of the triangle:');

area=(h*b)/2;

fprintf('The area of the right triangle is %0.2f. ',area );

Sample Output on MATLAB

Area of Right Triangle

Enter the height of the triangle:3

Enter the base of the triangle:3

The area of the right triangle is 4.50. >>

areaObliqueTriangle.m
clc;

disp('Area of Oblique Triangle');

h=input('Enter the height of the triangle:');

b=input('Enter the base of triangle:');

angle=input('Enter the angle of triangle:');

Area=(h*b*sin(angle))/2;

fprintf('The area of the oblique triangle is %0.2f.


',area );

Sample Output on MATLAB

Area of Oblique Triangle


Enter the height of the triangle:7

Enter the base of triangle:5

Enter the angle of triangle:pi/2

The area of the oblique triangle is 4.50. >>

areaCircle.m
clc;

disp('Area of the Circle);

r=input('Enter the radius of the circle: ');

area=pi*r^2;

fprintf('The area of the circle is %0.2f. ',area );

Sample Output on MATLAB

Area of Circle

Enter the radius:7

The area of the circle is 153.94. >>

areaEllipse.m
clc;

disp('Area of the Ellipse');

major=input('Enter the major axis:');

minor=input('Enter the minor axis:');

area=pi*major*minor;

fprintf('The area of the ellipse is %0.2f. ',area );

Sample Output on MATLAB

Area of the Ellipse

Enter the major axis:6

Enter the minor axis:4


The area of the ellipse is 75.40. >>

4 perimeterSquare.m
clc;

disp('Perimeter of Square');

s=input('Enter the side of the square:');

perimeter=4*s;

fprintf('The perimeter of the square is %0.2f.


',perimeter);

Sample Output on MATLAB

Perimeter of Square

Enter the side of the square:4

The perimeter of the square is 16.00. >>

perimeterRectangle.m
clc;

disp('Perimeter of Rectangle');

length=input('Enter the length of the rectangle: ');

width=input('Enter the width of the rectangle :');

perimeter=2*length + 2*width;

fprintf('The perimeter of the rectangle is %0.2f.


',perimeter );

Sample Output on MATLAB

Perimeter of Rectangle

Enter the length of the rectangle: 5

Enter the width of the rectangle :3

The perimeter of the rectangle is 16.00. >>

perimeterRightTriangle.m
clc;

disp('Perimeter of Right Triangle');

h=input('Enter the height of triangle: ');

b=input('Enter the base of triangle: ');

perimeter=h+b+sqrt((h^2)+(b^2));

fprintf('The perimeter of the right triangle is %0.2f.


',perimeter );

Sample Output on MATLAB

Perimeter of Right Triangle

Enter the height of triangle: 8

Enter the base of triangle: 12

The perimeter of the right triangle is 34.42. >>

perimeterObliqueTriangle.m
clc;

disp('Perimeter of the Oblique triangle');

a=input('Enter side a: ');

b=input('Enter side b: ');

c=input('Enter side c: ');

perimeter=a+b+c;

fprintf('The perimeter of the oblique triangle is %0.2f.


',perimeter );

Sample Output on MATLAB

Perimeter of the Oblique triangle

Enter side a: 4

Enter side b: 5

Enter side c: 9
The perimeter of the oblique triangle is 18.00. >>

circumferenceCircle.m
clc;

disp('Circumference of Circle');

radius=input('Enter the radius of circle: ');

circumference=2*pi*radius;

fprintf('The circumference of circle is %0.2f.


',circumference );

Sample Output on MATLAB

Circumference of Circle

Enter the radius of circle: 7

The circumference of circle is 43.98. >>

circumferenceEllipse.m
clc;

disp('Circumference of Ellipse');

maj=input('Enter the major axis of ellipse: ');

min=input('Enter the minor axis of ellipse: ');

circumference=pi*((3*(maj+min))-sqrt((3*(maj)+min)+
(maj+3*(min))));

fprintf('The circumference of the ellipse is %0.2f.


',circumference );

Sample Output on MATLAB

Circumference of Ellipse

Enter the major axis of ellipse: 7

Enter the minor axis of ellipse: 4

The circumference of the ellipse is 82.83. >>

5 volumeCone.m
clc;

disp('Volume of a Cone');

r=input('Enter the radius of the cone: ');

h=input('Enter the height of the cone: ');

volume=pi*(r^2)*(h/3);

fprintf('The Volume of the cone is %0.2f. ',volume );

Sample Output on MATLAB

Volume of a Cone

Enter the radius of the cone: 5

Enter the height of the cone: 7

The Volume of the cone is 183.26. >>

volumeSphere.m
clc;

disp('Volume of a Sphere');

r=input('Enter the radius of the sphere: ');

volume=pi*(r^3)*(4/3);

fprintf('The Volume of the sphere is %0.2f. ',volume );

Sample Output on MATLAB

Volume of a Sphere

Enter the radius of the sphere: 11

The Volume of the sphere is 5575.28. >>

volumeRectangularParallelepiped.m
clc;

disp('Volume of the Rectangular Parallelepiped');

h=input('Enter the height of the Rectangular


Parallelepiped: ');

l=input('Enter the length of the Rectangular


Parallelepiped: ');

w=input('Enter the width of the Rectangular Parallelepiped:


');

volume=h*l*w;

fprintf('The Volume of the Rectangular Parallelepiped is


%0.2f. ',volume );

Sample Output on MATLAB

Volume of the Rectangular Parallelepiped

Enter the height of the Rectangular Parallelepiped: 10

Enter the length of the Rectangular Parallelepiped: 7

Enter the width of the Rectangular Parallelepiped: 1

The Volume of the Rectangular Parallelepiped is 70.00. >>

volumeRightCircularCylinder.m
clc;

disp('Volume of a Right Circular Cylinder');

h=input('Enter the height of the Right Circular Cylinder:


');

r=input('Enter the radius of the Right Circular Cylinder:


');

volume=pi*(r^2)*h;

fprintf('The Volume of the Right Circular Cylinder is


%0.2f. ',volume );

Sample Output on MATLAB

Volume of a Right Circular Cylinder

Enter the height of the Right Circular Cylinder: 8

Enter the radius of the Right Circular Cylinder: 4


The Volume of the Right Circular Cylinder is 402.12. >>

volumeCube.m
clc;

disp('Volume of a Cube');

s=input('Enter the side of the cube: ');

volume=s^3;

fprintf('The Volume of the Cube is %0.2f. ',volume );

Sample Output on MATLAB

Volume of a Cube

Enter the side of the cube: 11

The Volume of the Cube is 1331.00. >>

6 surfaceareaCone.m
clc;

disp('Surface Area of Cone');

r=input('Enter the radius of base circle of cone: ');

h=input('Enter the slant height of cone: ');

SA=pi*r*h + pi*(r^2);

fprintf('The surface area of cone is %0.2f. ',SA);

Sample Output on MATLAB

Surface Area of Cone

Enter the radius of base circle of cone: 11

Enter the slant height of cone: 8

The surface area of cone is 656.59. >>

surfaceareaSphere.m
clc;
disp('Surface Area of Sphere');

r=input('Enter radius of sphere: ');

SA=4*pi*r^2;

fprintf('The surface area of sphere is %0.2f.',SA );

Sample Output on MATLAB

Surface Area of Sphere

Enter radius of sphere: 9

The surface area of sphere is 1017.88.>>

surfaceareaRectangularParallelepiped.m
clc;

disp('Surface Area of a Rectangular Parallelepiped');

a=input('Enter the width of rectangular parallelepiped: ');

b=input('Enter the height of rectangular parallelepiped:


');

c=input('Enter the length of rectangular parallelepiped:


');

SA=2*(a*b+a*c+b*c);

fprintf('The surface area of rectangular parallelepiped is


%0.2f. ',SA );

Sample Output on MATLAB

Surface Area of a Rectangular Parallelepiped

Enter the width of rectangular parallelepiped: 8

Enter the height of rectangular parallelepiped: 12

Enter the length of rectangular parallelepiped: 68

The surface area of rectangular parallelepiped is 2912.00. >>

surfaceareaRightCircularCylinder.m
clc;

disp('Surface Area of a Right Circular Cylinder');

r=input('Enter the radius of cylinder: ');

h=input('Enter the height of cylinder: ');

SA=2*pi*r*h+2*pi*r^2;

fprintf('The surface area of cylinder is %0.2f. ',SA );

Sample Output on MATLAB

Surface Area of a Right Circular Cylinder

Enter the radius of cylinder: 7

Enter the height of cylinder: 12

The surface area of cylinder is 835.66. >>

surfaceareaCube.m
clc;

disp('Surface Area of a Cube');

a=input('Enter the side of cube: ');

SA=6*a^2;

fprintf('The surface area of cube is %0.2f. ',SA );

Sample Output on MATLAB

Surface Area of a Cube

Enter the side of cube: 13

The surface area of cube is 1014.00. >>

7 Rectangle.m
disp('Area and Perimeter of the Rectangle');

choose=input('n 1. Area of the Rectangle \n 2. Perimeter of


the Rectangle \n Choose 1 or 2: ');

switch(choose)
case 1;

length=input('Enter the length of the rectangle:


');

width=input('Enter the width of the rectangle :');

area=length*width;

fprintf('The area of the rectangle is %0.2f. ',


area);

case 2;

length=input('Enter the length of the rectangle:


');

width=input('Enter the width of the rectangle: ');

perimeter=2*length + 2*width;

fprintf('The perimeter of the rectangle is %0.2f.


', perimeter);

end

Sample Output on MATLAB

>> Rectangle

Area and Perimeter of the Rectangle

n 1. Area of the Rectangle

2. Perimeter of the Rectangle

Choose 1 or 2: 1

Enter the length of the rectangle: 1

Enter the width of the rectangle :2

The area of the rectangle is 2.00. >>

>> Rectangle

Area and Perimeter of the Rectangle

n 1. Area of the Rectangle

2. Perimeter of the Rectangle


Choose 1 or 2: 2

Enter the length of the rectangle: 1

Enter the width of the rectangle: 3

The perimeter of the rectangle is 8.00. >>

8 solidMensuration.m
clc;

disp('Plane Figures and Solid Figures');

choose=input('\n 1. Plane Figures \n 2. Solid Figures \n\n


Choose: ');

switch(choose)

case 1;

disp('Plane Figures');

disp(' 1. Square');

disp(' 2. Rectangle');

disp(' 3. Right Triangle');

disp(' 4. Oblique Triangle');

disp(' 5. Circle');

plane = input('\nChoose: ');

switch(plane)

case 1;

disp(' 1. Area ')

disp(' 2. Perimeter');

choose1=input ('Choose: ');

switch(choose1)

case 1;

disp('Area of the Square');

s=input('Enter the side of the square: ');


area=s^2;

fprintf('The area of the square is %0.2f. ',area );

case 2;

disp(' Perimeter of the square ');

a=inpit('Enter the side length of the square: ');

perimeter=4*a;

fprintf('The perimeter of the square is


%0.2f.',perimeter);

end

case 2;

disp(' 1. Area ')

disp(' 2. Perimeter');

choose2=input ('Choose: ');

switch(choose2)

case 1;

disp(' Area of rectangle');

l=input('Enter the length of the rectangle: ');

h=input('Enter the height of the rectangle: ');

area=l*h;

fprintf('The area of the rectangle is %0.2f.


',area );

case 2;

disp(' Perimeter of rectangle');

l=input('Enter the length of the rectangle: ');

h=input('Enter the height of the rectangle: ');

perimeter=2*l+2*h;

fprintf('The perimeter of the rectangle is %0.2f.


',perimeter );
end

case 3;

disp(' 1. Area ')

disp(' 2. Perimeter');

choose3=input ('Choose: ');

switch(choose3)

case 1;

disp('Area of the Right Triangle');

base=input('Enter the base of the right Triangle:


');

height=input('Enter the height of the right


Triangle: ');

area=0.5*base*height;

fprintf('The area of the right triangle is %0.2f.


',area);

case 2;

disp('Perimeter of the Right Triangle');

base=input('Enter the base of the right Triangle:


');

height=input('Enter the height of the right


Triangle: ');

c=sqrt(base^2+height^2);

perimeter=base+height+c;

fprintf('The perimeter of the triangle is %0.2f.


',perimeter );

end

case 4;

disp(' 1. Area ')

disp(' 2. Perimeter');

choose4=input ('Choose: ');


switch(choose4)

case 1;

disp('Area of Oblique Triangle');

h=input('Enter the height of the triangle:');

b=input('Enter the base of triangle:');

angle=input('Enter the angle of triangle:');

Area=(h*b*sin(angle))/2;

fprintf('The area of the oblique triangle is %0.2f.


',area );

case 2;

disp('Perimeter of the Oblique triangle');

a=input('Enter side a: ');

b=input('Enter side b: ');

c=input('Enter side c: ');

perimeter=a+b+c;

fprintf('The perimeter of the oblique triangle is


%0.2f. ',perimeter );

end

case 5;

disp(' 1. Area ')

disp(' 2. Circumference');

choose5=input ('Choose: ');

switch(choose5)

case 1;

disp('Area of the circle');

r=input(' Enter the radius of the circle: ');

area=pi*r^2;

fprintf('The area of the circle is %0.2f. ',area );


case 2;

disp('Circumference of the circle');

rad=input(' Enter the radius of the circle: ');

perimeter=pi*rad*2;

fprintf('The Circumference of the circle is %0.2f.


',perimeter );

end

end

case 2;

disp('Solid Figures');

disp('1. Cone ');

disp('2. Sphere ');

disp('3. Rectangular Parallelepiped ');

disp('4. Right Circular Cylinder ');

disp('5. Cube ');

solid=input('\nChoose: ');

switch(solid)

case 1;

disp(' 1. Volume ')

disp(' 2. Surface Area');

choose1s=input('Choose: ');

switch(choose1s)

case 1;

disp('Volume of the Cone');

h=input('Enter the height of the cone: ');

r=input('Enter the radius of the cone: ');

volume=(1/3)*pi*(r^2)*h;
fprintf('The volume of the cone is %0.2f.
',volume );

case 2;

disp('Surface Area of the Cone');

h=input('Enter the height of the cone: ');

r=input('Enter the radius of the cone: ');

SA=pi*r*h + pi*(r^2);

fprintf('The surface area of the cone is %0.2f.


',SA );

end

case 2;

disp(' 1. Volume ')

disp(' 2. Surface Area');

choose2s=input ('Choose: ');

switch(choose2s)

case 1;

disp('Volume of the Sphere');

r=input('Enter the radius of sphere: ');

volume=(4/3)*pi*(r^3);

fprintf('The volume of the Sphere is %0.2f.


',volume );

case 2;

disp('Surface Area of the Sphere');

r=input('Enter the radius of sphere: ');

SA=4*pi*(r^2);

fprintf('The Surface area of the Sphere is %0.2f.


',SA );

end

case 3;
disp(' 1. Volume ')

disp(' 2. Surface Area');

choose3s=input ('Choose: ');

switch(choose3s)

case 1;

disp(' Volume of rectangular parallelepiped');

l=input('Enter the length of the rectangular


parallelepiped: ');

w=input('Enter the width of the rectangular


parallelepiped: ');

h=input('Enter the height of the rectangular


parallelepiped: ');

volume=l*w*h;

fprintf('The volume of the rectangular parallelepiped


is %0.2f. ',volume );

case 2;

disp(' Surface area of rectangular parallelepiped');

l=input('Enter the length of the rectangular


parallelepiped: ');

w=input('Enter the width of the rectangular


parallelepiped: ');

h=input('Enter the height of the rectangular


parallelepiped: ');

SA=2*l*w + 2*l*h+2*w*h;

fprintf('The surface area of the rectangular


parallelepiped is %0.2f. ',SA );

end

case 4;

disp(' 1. Volume ')

disp(' 2. Surface Area');

choose4s=input ('Choose: ');


switch(choose4s)

case 1;

disp(' Volume of right circular cylinder');

r=input('Enter the radius of the right circular


cylinder: ');

h=input('Enter the height of the right circular


cylinder: ');

volume=pi*(r^2)*h;

fprintf('The volume of the right circular cylinder


is %0.2f. ',volume );

case 2;

disp(' Surface area of right circular cylinder');

r=input('Enter the radius of the right circular


cylinder: ');

h=input('Enter the height of the right circular


cylinder: ');

SA=2*pi*r*h + 2*pi*(r^2);

fprintf('The surface area of the right circular


cylinder is %0.2f. ',SA );

end

case 5;

disp(' 1. Volume ')

disp(' 2. Surface Area');

choose5s=input ('Choose: ');

switch(choose5s)
case 1;

disp(' Volume of the cube ');

a=input('Enter the side length of the cube: ');

volume=a^3;

fprintf('The volume of the cube is %0.2f.


',volume );

case 2;

disp(' Surface area of the cube ');

a=input('Enter the side length of the cube: ');

SA=6*(a^2);

fprintf('The surface area of the cube is %0.2f. ',SA


);

end

end

end

7. Conclusion:
I therefore conclude that MATLAB is so versatile that it cannot just compute matrices and differential
equations, but also solid mensuration problems. By making use of the script window and making an m file,
you just have to write the formula and make questions where you have to input the necessary conditions to
fulfill the formula. This laboratory exercise made me further understands the functions of MATLAB and its
features. Thanks to this laboratory experiment, I could now make a solid mensuration calculator (solving for
the diameter, circumference, surface area and volume) by just typing codes!
8. Assessment (Rubric for Laboratory Performance):

Вам также может понравиться