Skip to main content

Posts

Showing posts with the label volume

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...

Volume of a solid sphere and graph for different radius using Matlab

Program Calculate the volume of a solid sphere based on the user input given and also plot a graph for different values of radius with an interval of 0.5 and range of [r-5,r+5]. The relation for the volume of the sphere is given by: Volume of a sphere Where r is the radius of the sphere You can learn more about sphere from here:  1) Sphere - mathsisfun.com 2) Sphere- Wolfram Solution First of all let us understand the question before go into solving the problem using Matlab . 1) The question says that we will have to calculate the volume of a sphere by taking the input of the value of the radius from the user. 2) The question also asks us to draw the graph for a given set of range with a given set of interval . So the question asks us to take radius on x axis and volume on y axis . Next the difference between two points on the x axis should be 0.5 as said by the interval and finally we will have to draw the graph in the range [r-5,r+5]. Lets understand th...