Create a script that creates a random vector

Assignment Help MATLAB Programming
Reference no: EM131055833

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.

Reference no: EM131055833

Questions Cloud

What is the firm cost of retained earnings : The firm has net income of $2 million, Sales of $15 million, total assets of $14 million, common equity of $9 million, and common dividend of $1 million, and 1 million shares outstanding with a total market value of $23 million. What is the firm's co..
Confidence interval for the true proportion of high school : Dylan wants to determine a 99 percent confidence interval for the true proportion of high school students in the area who attend their home basketball games. How large of a sample must he have to get a margin of error less than 0.04? [To find n, u..
What is the standard deviation of the revised portfolio : Research reported in the chapter shows that the correlation between the U.S. and Japanese stock markets is 0.35. Assume that the standard deviations of the two markets are 15 percent and 18 percent, respectively. What is the variance of the revised p..
Describe what working capital practices : Describe what working capital practices, including methods of capital budgeting analysis techniques. Analyze the potential pitfalls in capital budgeting practices that a business should be aware of. Develop a simple statement of cash flows for the bu..
Create a script that creates a random vector : 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..
Annual interest tax shield and debt issuance : In recent years, Haverhill Corporation has averaged a net income of $10 million per year on net sales of $100 million per year. It currently has no long-term debt, but is considering a debt issue of $5million. The interest rate on the debt would be 6..
Confidence the proportion of all americans : In a random sample of 750 Americans, 39.1% indicated that they have a cat for a pet. Estimate with 93% confidence the proportion of all Americans that have cats as pets. (Give the confidence interval in percentages.)
The public needs to know - revised version : Your boss has asked you (a communication specialist) to write an informative paper about the free clinic that will be opening in your local neighborhood for those without medical insurance. Describe the process and benefits of the program for the..
What is the YTM of the bond : Norma has one share of stock and one bond. The total value of the two securities is 1,466.4 dollars. The stock pays annual dividends. The next dividend is expected to be 5.37 dollars and paid in one year. In two years, the dividend is expected to be ..

Reviews

Write a Review

MATLAB Programming Questions & Answers

  Create a script file for conversion of temperature

Create a script file for conversion of temperatures. Use the input function or menu function to allow the user to enter temperature scale of Fahrenheit, Celsius, Kelvin, or Rankine. If you are using the input function, tell the user to enter F for Fa..

  Plot the angular velocity of the pendulum

Plot the angle of the pendulum as calculated from all three ODE solver methods on a single plot, ensuring that the plot is titled, all axes are labelled, units are indicated, and the legend for each solver displayed in Best configuration.

  Derive and solve a model of an insulated water tank

Determine the steady state conditions at t

  Why does matlab keep telling that you need input arguments

how do you solve this problem and why does MATLAB keep telling that you need more input arguments - Create a function that returns true if the input is a numeric array and false otherwise

  Develop your own matlab function for the fixed-point method

Develop your own Matlab function for the Fixed-point method. Use the approximate relative error as your stopping criterion. The first line of your function should be function [root,froot,ea,iter] = fixedpoint(func,xr,es,maxit)

  Write a matlab function newtonraphson

Write a MATLAB function newtonRaphson(fx, x0, sigfig, maxIT) that will return a root of the function f(x) near x=x0 using the Newton-Raphson method, where sigfig is the accuracy of the solution in terms of significant figures

  Use the sandp 500 excess returns and inflation

Use the S&P 500 excess returns and inflation to predict Intel stock excess returns. Provide the regression equation for the Intel stock excess returns when using S&P 500 excess returns and inflation as explanatory variables.

  Create functions in file

Create Functions in File and how to code this function - Declare function inputs, and outputs

  Function that takes as input parameters

Define a function that takes as input parameters a function handle f, start and end values a and b, and a number of steps n. The function should compute and return the x and y values of the maximum of the function over the range a to b.

  Modify the matlab code

understand the 2-D solution of the Laplace's equation in Examples 6.5 and 6.6 in your text book. Then modify the MATLAB code provided at the end of the example, and use it to draw the equipotential lines as well as the flux lines on two different ..

  The function should compute and return

Define a function that takes as input parameters a function handle f, start and end values a and b, and a number of steps n. The function should compute and return the x and y values of the maximum of the function over the range a to b.

  Simulate using matlab a casino style game

Your assignment requires you to simulate, using Matlab, a casino style game of chance. In theory these games are completely governed by the rules of probability and should be able to be simulated by the use of random number generators

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd