Question

Based on your understanding of function M-file, create a function that can compute the volume of...

Based on your understanding of function M-file, create a function that can compute the volume of a cylinder. Execute your function file for (radius, height) values of (2,5), (3,7) and (5,10)

Can someone help me with this? It is for Matlab.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The above problem can be solved in the following steps-

STEP 1- First define the function volume_of_cylinder(radius, height) in the filename volume_of_cylinder.m.

This has to be done because script name and function name should be same.

STEP 2 - This function takes in two input parameters, radius and height and returns volume value

STEP 3- In the funciton, using the formula vol = \Pi r^{2}h we compute the volume of cylinder

STEP 4- After executing the script file, we will call the funtion defined above from the command window with different radius and height values and see the output as shown below.

MATLAB CODE-

volume_of_cylinder.m

%define the function to calculate the volume of cylinder
%it takes in radius and height as input parameters
%and returns volume as vol of cylinder
%formula is volume of cylinder = pi * r^2 * h
function volume = volume_of_cylinder(radius, height)
%using the formula to compute the volume of cylinder,
%store the volume in the returning variable
volume = pi*(radius^2)*height;
end

IMAGE OF CODE-

volume_of_cylinder.m

1585777063255_image.png

OUTPUT-

On the command window, call the defined function volume_of_cylinder() with the radius and height values as shown below

Command Window >> volume of cylinder (2,5) ans = 62.8319 >> volume of cylinder (3,7) ans = 197.9203 >> volume of cylinder (5,

If this answer helps, please give an up vote and feel free to comment for any query.

Add a comment
Know the answer?
Add Answer to:
Based on your understanding of function M-file, create a function that can compute the volume of...
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
  • how to do the fun1.m function? 1.1 Part 1 First, learn how to create a function...

    how to do the fun1.m function? 1.1 Part 1 First, learn how to create a function in MATLAB. Given the function U(T) = 0.12 – 2 sin(1) Create a MATLAB function that you can call from the main *.m file. Use the MATLAB Help by typing help function to learn about it. There are more than one way to create a function in MATLAB. For this lab, use the most basic one, i.e., by creating a function file that contains...

  • The volume of a right circular cylinder is calculated by Trh where ris radius and his...

    The volume of a right circular cylinder is calculated by Trh where ris radius and his height Write a user-defined MATLAB function to compute the volume given radius and height. For the function name and arguments use Volume - Volume cylinder (Radius, Height). You do not need to call the function, you need to write the function as is would be in your current folder available to be called from a program. The function will take in the indicated inputs,...

  • create a m file to calculate the transfer function based on poles and amplitudes

    create a m file to calculate the transfer function based on poles and amplitudes

  • use MatLab to answer these questions 1. (10 points) Create an m-file called addup.m Use a...

    use MatLab to answer these questions 1. (10 points) Create an m-file called addup.m Use a for loop with k = 1 to 8 to sum the terms in this sequence: x(k) = 1/3 Before the loop set sumx = 0 Then add each term to sumx inside the loop. (You do not need to store the individual values of the sequence; it is sufficient to add each term to the sum.) After the loop, display sumx with either disp()...

  • 11. Create your own MATLAB function file using Power Method to find the largest eigenvalue. A...

    11. Create your own MATLAB function file using Power Method to find the largest eigenvalue. A matrix and an initial guess can be the inputs and the output should be the largest eigenvalue. Please send the file by email. 11. Create your own MATLAB function file using Power Method to find the largest eigenvalue. A matrix and an initial guess can be the inputs and the output should be the largest eigenvalue. Please send the file by email.

  • Need help with these scenarios Question 1 Write a JavaScript program to get the volume of...

    Need help with these scenarios Question 1 Write a JavaScript program to get the volume of a Cylinder with four decimal places using object classes. Volume of a cylinder : V = πr2h where r is the radius and h is the height of the cylinder. Your solution must include an HTML and a JavaScript file, with a button to create the cylinder, inputs for the cylinder's radius and height and an output to show the cyclinder's volume. Your solution...

  • Urgent: Help with MatLab Program Create a Matlab function called seasonif. m which assigns to the...

    Urgent: Help with MatLab Program Create a Matlab function called seasonif. m which assigns to the numerical value of a month within the year a numerical value for the particular season in which that month occurs (see Table 2 above for numerical values to assign seasons). As usual, January is mouth 1, February is mouth 2, mid so on. Your function should allow decimal values (e.g. 4.68 should be considered part of April), but any value less than 1 or...

  • Write a regular function (i.e. in a function .m file) to calculate the series expansion of...

    Write a regular function (i.e. in a function .m file) to calculate the series expansion of cosine(x). The number of terms calculated in the series should be specified in the input list of the function. Write a separate function that determines when the series expansion begins to deviate by at least 10% from the true value of cosine(x) based on the number of terms calculated in the series expansion, n. For n = 1, 2, … 10, determine the values...

  • Create a Function file using Matlab. function sums = estimSum (nTerms) Before we go much further, save your file and na...

    Create a Function file using Matlab. function sums = estimSum (nTerms) Before we go much further, save your file and name it the exact name of the function, estimSum Inside the function file just created, write the code needed to compute partial sums 1)k+1 2k 1 k-1 and compare the output in each case to the value of by computing the remainder Rn- _Snl for each n - 20,50, 100, 1000. When calling the function in Matlab's command window for...

  • Create a function m-file for the following expression which has two inputs X and Y. Call...

    Create a function m-file for the following expression which has two inputs X and Y. Call it “zoom”. Z = eVX2+Y2 /(X + Y) This function (zoom) can be in a separate script or as the last cell in your main m-file (which includes all of your solutions). Use Zoom to generate values for Z for X and Y values varying from 1 to 4 with an increment of 0.2. Also generate a table that includes all values for X...

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