Create a function called hollowsphere that calculates the


Part 1. Basic Scripts

Problem I. Write a simple script that will calculate the volume of a hollow sphere. The volume can be calculated by using the following formula;

v=4Π/3 (ro3 - ri3)

Where r, is the inner radius and ro is the outer radius. Assign a value to a variable for the inner radius, and also assign a value to another variable for the outer radius. Then, using these variables, assign the volume to a third variable. Your script should accept user input. Print your results using an fprintf statement.

Problem 2. Create a function called "hollowSphere" that calculates the volume using the formula shown in Problem I. Then write a script that prompts the user for the value of the inner radius and outer radius, your script will then call the function that you created to calculate the hollow sphere area. Print your results using an fprintf statement from your script.

Part 2. Plotting

Problem 1. Create a script that creates a random vector with 50 integer values in the range 1 - 20 and assigns the result to r,. Creates a random vector with 50 integer values in the range 30 - 50 and assigns the result to ro. Create a scatterplot of volume vs r,, and a second scanerplot of volume vs ro. Add labels to your x and y axis. Add titles to the plots. The first plot should have red circles, and the second plot should have blue squares as the markers. Lastly, create a third plot that plots volume vs ri and ro, add a legend to this plot. Make sure you are using your "hollowSphere" function. Also, you will need to modify the function operators to be element wise operators as shown below;

volume = ( (4*pi) /3)* (ro3 - ri3) ;

Part III. If Structures

Problem 1. The script that was developed in Part I did not considered checking for errors. In this specific problem, we want to allow the user to enter any value of the inner and outer radius as long as the value of the inner radius is smaller than that of the outer radius. Therefore, we must modify the script in Part I Problem 2 to check for this condition. If the user enters a value of ro that is smaller than r, we want to display a message that tells the user that the values are invalid and that we will swap the them. Swap the values of ni and n and allow your script to calculate and print the results. (Hint: when swapping the values, you are assigning the original value of r.) tor, and vice versa. You will find it necessary to use a third value that stores a temporary value). Make sure you are using your "hollowSphere" function.

Problem 2. Now consider the situation in which the user enters a negative value for either ri or ro, clearly this is wrong and should be avoided. Therefore, if the user enters a negative value for either of the variables, the script will display a message stating that the input values are invalid but we will convert them to positive. If either of the input values are negative, make them positive. Then check for the conditions in the previous problem (i.e. ra should be greater than ri) and continue with the calculations as usual. Make sure you are using your "hollowSphere" function.

Expectations: All scripts should have your name and comments about the different parts of the script. Your work should be original and be your own. No teamwork is allowed in this Exam. Each problem is solved using a separate script file, with the exception of any function that you created, as functions can be called by any script and do not require duplication.

You must submit your an files and zip them in an archive before submitting.

Request for Solution File

Ask an Expert for Answer!!
MATLAB Programming: Create a function called hollowsphere that calculates the
Reference No:- TGS01401674

Expected delivery within 24 Hours