Skip to main content

Posts

Showing posts with the label square

Volume of pyramid in using Matlab

Problem Write a script to calculate the volume of a pyramid, which is 1/3 * base * height,  where the base is length * width. Prompt the user to enter values for the length,  width, and height, and then calculate the volume of the pyramid. When the user  enters each value, he or she will then also be prompted for ‘i’ for inches or ‘c’ for  centimeters. (Note: 2.54 cm  = 1 inch.) The script should print the volume in cubic  inches with three decimal places. As an example, the output format will be: This program will calculate the volume of a pyramid. Enter the length of the base: 50 Is that i or c? i Enter the width of the base: 6 Is that i or c? c Enter the height: 4 Is that i or c? i The volume of the pyramid is xxx.xxx cubic inches. Solution This problem has been taken from the book A Practical introduction to Matlab by stormy Attaway . This is a must read book for Matlab programmers. This will make your path to success in Matlab easy and y...

Area of rectangle, square, circle and triangle using Matlab

Problem Ask the user to give input to select the rectangle or square or circle or triangle and then ask the user necessary input. Finally calculate the area of the selected geometrical figure using Matlab. The areas of the polygons(circle can also be called as a polygon with infinite sides) is as follows: 1) Area of  Rectangle : Area of Rectangle Formula Where L is the length and B is the breadth of the rectangle 2) Area of square : Area of square Formula Where a is the length of the side of a square 3) Area of circle : Area of a circle Where r is the radius of the circle 4) Area of triangle : Where b is the length of the base of triangle and h is the height of the triangle. If you want to more about the geometric polygons then you can see: 1) Rectangle 2) Square 3) Circle 4) Triangle Solution The solution is very simple if you know what the above figures mean. But if you don't remember the figure then you can see the images below to g...