Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Nay programming languge is fine (MatLab, Octave, etc.) This is the whole document this last picture i sent is the first page 5. Write and

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Nay programming languge is fine (MatLab, Octave, etc.)
This is the whole document this last picture i sent is the first page image text in transcribed
5. Write and save a function Sphere Area that accepts Radius as input argument, and returns SurfaceArea (4 tt r) as output argument. Paste the function code below. Paste code here 6. Validate your Sphere Area function from the command line, checking the results against hand calculations. Paste the command line code and results below. 7. Design an algorithm in pseudocode for a program (script file) that will prompt a user for the radius value, call each of the functions, and then output the values of surface area, volume, and surface-to volume ratio (all formatted to 2 decimal places). 8. Program your algorithm, and paste the code for the main program below. Your program must contain the lines of code indicated below, exactly as written: Paste code here Vol - SphereVol (SRadius); Shrea - SphereArea (SRadius); SVRsphere - Sarea / svol; (add some relevant comment) (add some relevant comment) (add some relevant comment) 9. Test the program. Paste output for radius values of 4 and 0 (what happens here? Why?). 10. Modify your functions so that they will accept vector input for the radius. Validate your functions from the command line by setting the variable SRodius 0:2 and then calling each function using SRadius. (Verify that the results are correct for each.) Paste here the portion of your code that was changed, and evidence that your functions work properly. Altered code from Spherevol: Validation of Spherevol function: Altered code from Sphere Area: Validation of Sphere rea function: 11. Modify your program from #8 above so that the user inputs a minimum and a maximum value for the radius. The program should then create a radius vector with 20 values from min to max, perform the necessary calculations, and instead of outputting to the screen write all of the results as a table to a file sphere.dot. The table should have 20 rows and Columns, which correspond to (in order): radius, area, volume, and surface-to-volume ratio. (Note that you will first need to create a single matrix containing all of the data) Paste code here 12. Verify your results using >> type sphere.dat and checking a few rows of values (paste the first few rows here). 13. Create a new program (script file) that loads the data from the sphere.dat file, puts the first column into a SRadius vector, puts the last column into a SVRsphere vector, and generates a plot of surface-to-volume ratio versus radius (remember axis labels and a title). Paste your code and the generated plot below. Paste code here Paste plot here: 14. What happens to the surface-to-volume ratio of a sphere as the size of the sphere (radius) Increases? 15. Create a new function Cylvol that accepts both the radius and height of a cylinder as input arguments, and then returns its volume (it rh). Assume that radius will be a vector, while height will be a single (scalar) value. Test your function by calling it from the Paste code here Paste output for (a) Paste output for (b) 16. Create a function CylArea to calculate the surface area of a cylinder (20 + 2x r h) for inputs of radius and height. Again, assume that radius will be a vector, while height will be a scalar. And test your function from the command line Paste code here Paste output for a Vaste output for 17. Open your script file from question #11 above and save it under a new name. In addition to the user prompts for min and max values of radius (you will continue to create a vector of 20 radius values from this), add a prompt for the cylinder height. Add function calls to CylVol and CylArea, and use the outputs to calculate the surface-to- volume ratios for the cylinders (note that each function output will be a vector). Finally, get rid of the earlier statements associated with the data file, and instead simply create a plot of surface-to-volume ratio versus radius that contains 2 curves, one for spheres and one for cylinders, both plotted on the same graph. Type help plot for a description of how to do this. Be sure that the plot is properly labeled, and add a legend to identify the curves. Test your program for rmin = 1, rmax = 5, and h = 10, and verify that it works properly. Paste the final successful code and plot below. Paste code here Paste plot here: 5. Write and save a function Sphere Area that accepts Radius as input argument, and returns SurfaceArea (4 ar?) as output argument. Paste the function code below. Paste code here 6. Validate your Sphere Area function from the command line, checking the results against hand calculations. Paste the command line code and results below. 7. Design an algorithm in pseudocode for a program (script file) that will prompt a user for the radius value, call each of the functions, and then output the values of surface area, volume, and surface-to-volume ratio (all formatted to 2 decimal places) 8. Program your algorithm, and paste the code for the main program below. Your program must contain the lines of code indicated below, exactly as written: Paste code here SVol - SphereVol (SRadius); SArea - SphereArea (SRadius): (add some relevant comment) (add some relevant comment) (add some relevant comment) SVRsphere - SArea / Svol; 9. Test the program. Paste output for radius values of 4 and 0 (what happens here? Why?). 10. Modify your functions so that they will accept vector input for the radius. Validate your functions from the command line by setting the variable SRadius = 0:2 and then calling each function using SRadius. (Verify that the results are correct for each.) Paste here the portion of your code that was changed, and evidence that your functions work properly. Altered code from Spherevol: Validation of SphereVol function: Altered code from SphereArea: Validation of SphereArea function: 11. Modify your program from #18 above so that the user inputs a minimum and a maximum value for the radius. The program should then create a radius vector with 20 values from min to max, perform the necessary calculations, and instead of outputting to the screen, write all of the results as a table to a file sphere.dat. The table should have 20 rows and 4 columns, which correspond to (in order): radius, area, volume, and surface-to-volume ratio. (Note that you will first need to create a single matrix containing all of the data.) Paste code here 12. Verify your results using >> type sphere.dat and checking a few rows of values (paste the first few rows here). 13. Create a new program (script file) that loads the data from the sphere.dat file, puts the first column into a SRadius vector, puts the last column into a SVRsphere vector, and generates a plot of surface-to-volume ratio versus radius (remember axis labels and a title). Paste your code and the generated plot below. Paste code here Paste plot here: 14. What happens to the surface-to-volume ratio of a sphere as the size of the sphere (radius) increases? 15. Create a new function Cylvol that accepts both the radius and height of a cylinder as input arguments, and then returns its volume (rh). Assume that radius will be a vector, while height will be a single (scalar) value. Test your function by calling it from the command line with the following values for r and h. (calculate values by hand to verify) Modify your function as needed so that the output is correct. (a) r = 2, h = 3 (b) r = [012], h = 3 Paste your final code here, as well as the output for inputs of (a) and (b) above. Paste code here Paste output for (a) Paste output for (b) 16. Create a function CylArea to calculate the surface area of a cylinder (21 r2 + 27tr h) for inputs of radius and height. Again, assume that radius will be a vector, while height will be a scalar. And test your function from the command line Paste code here Paste output for (a) Paste output for (b) 17. Open your script file from question #11 above and save it under a new name. In addition to the user prompts for min and max values of radius (you will continue to create a vector of 20 radius values from this), add a prompt for the cylinder height. Add function calls to Cylvol and CylArea, and use the outputs to calculate the surface-to- volume ratios for the cylinders (note that each function output will be a vector). Finally, get rid of the earlier statements associated with the data file, and instead simply create a plot of surface-to-volume ratio versus radius that contains 2 curves, one for spheres and one for cylinders, both plotted on the same graph. Type help plot for a description of how to do this. Be sure that the plot is properly labeled, and add a legend to identify the curves. Test your program for rmin = 1, rmax = 5, and h = 10, and verify that it works properly. Paste the final successful code and plot below. Paste code here Paste plot here: For the following lab exercise, work in groups of 2 to 3 and submit one copy of the completed assignment for each group (list names of all group members above). Type your answers to questions and paste any code, output, and graphs from MATLAB, directly into this Word document. When you have completed the assignment, upload the finished document to the indicated location on the course website. In this lab, you will write MATLAB functions that calculate the surface areas, volumes, and surface-to- volume ratios of regular geometric solid shapes. You will experiment with using these functions in a stand-alone format, as well as calling them from other programs. In the process, you will write to and read from data files, create plots, and analyze the geometrical relationships for these solid shapes. 1. In the MATLAB Editor, save a new function m-file under the name SphereVol.m and type in the following code exactly as it appears: function Volume = SphereVol ( Radius) % Calculates the Volume of a sphere that has a specified value of Radius Volume = (4/3) * pi * Radius ^3; end 2. What is the function name? __ Input argument? _ Output argument?__ 3. After saving your function, test it from the command line with the following function call. (Verify with a calculation by hand that your result is correct.) Indicate the result. >> SphereVol (1) Result? Describe in detail the sequence of operations that took place in the computer as a result of the command above (you should list at least 5 steps). 4. Test your function again from the command line using the following two commands: >> SRadius = 1; >> Sphere Vol (SRadius) Result? Note that the variable used at the command line has the name SRadius, while that in the function is Radius. Why does it not matter that these variables have different names

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

m Lets add the electrical harness for the automobile at step 12.

Answered: 1 week ago

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago