Write a script m-file called hw4

Assignment Help Programming Languages
Reference no: EM131104622

Write a script m-file called hw4.m. Label your solution to each exercise with a comment. Some of the exercises ask for additional script m-files that will be called from within hw4.m.

1. Write a script called 'prob1.m' that solves for the variables y, and z in terms of a user inputed x. The variables y and z are defined as follows:

2.

3. y = x - 30            when 0 < x < 100

4.   = 0.20*x + 800      when x > 100

5.   = -50               otherwise

6.

7.

8. z = -1                when x < 0

9.   =  0                when x = 0

10.        =  1                when x > 0

Your script should prompt the user to input a value of x (use the input function). Next it should compute the values of y and z (surpress the output at first). Finally it should explicitly display the values of x, y, and z.
From with the 'hw4.m' script call 'prob1.m'.
2. Write a script called 'prob2.m' that asks the user if they wish to clear the variables in the workspace. If the user responds with the strings 'y' or 'yes' then the workspace should be cleared. After the workspace is cleared the script should display the string 'Workspace cleared.' If the user responds with the strings 'n' or 'no' then the work space should not be cleared and the script should display the string 'Workspace not cleared.' If the user enters anything else, the script should say that the 'Input was not understood.' You should implement this using an if-else construction.
In the file 'hw4.m' first issue a command that lists all the variables currently in the workspace. Then execute execute 'prob2.m'. Finally, to see if your script did what it was supposed to, redisplay a list of all the variables in the workspace.
3. Write a script called 'prob3.m' that does the same thing as the previous question except that it makes use of a switch-case construct instead of an if-else.
In the file 'hw4.m' first issue a command that lists all the variables currently in the workspace. Then execute execute 'prob3.m'. Finally, to see if your script did what it was supposed to, redisplay a list of all the variables in the workspace.
4. Write a function called triple (in a file called 'triple.m'). That takes a single variable x and returns a single variable in which every element of x is multiplied by 3. Make sure to properly construct the help text for the function in the first comment block. Be sure to include an H1 line.
From within 'hw4.m' write a series of expressions that demonstrate the triple function being used a variety of input including both scalers and arrays. Also make sure to demonstrate that its help text works properly.
5. Write a function called threshold1 (in a file called 'threshold1.m'. The function takes three arguments. The first two are arbitrarily sized arrays, A and B, and the third is a postive scaler value, t. The function returns two variables, call them x and y.
The variable x should have the same elements as the variable A, except in every position where an element of A is larger than t, there should be a 0.
The variable y should have the same elements as the variable B, except in every position where an element of B is smaller than t, there should be a 0.
Be sure to properly comment your code.
From within 'hw4.m' write a series of expressions that demonstrate the threshold1 function being executed on at least two different sets of input.
6. Write a function called threshold2 (in a file called 'threshold2.m'). The function takes an arbitrary number of input variables. The first input variable, t, is required and is the threshold value. The remaining arguments are arbitrarily sized arrays. The function should return the same number of output variables as there are input arrays to threshold.
Each of the output variables should have the same elements as the corresponding input variable, except in every position where an input value is less than or equal to the threshold t, there should be a 0.
If the user doesn't specify enough output variables when calling this function, the function should generate a MATLAB error with a descriptive error message.
If the user doesn't specify enough input variables to fill all of the output variables requested, the remaining output variables should be set to NaN and a warning messaging (just using disp) should be displayed by the function.
Sample runs of this program might look like this:

>> z = 1:5;

>> a = threshold2(3,z) 

a =  0 0 0 4 5 

>> y = 1:6;

>> [a b] = threshold2(4,z,y)

 a =  0 0 0 0 5 

b =  0 0 0 0 5 6 

>> [a b c] = threhold2(4,z,y) 

a =  0 0 0 0 5 

b =  0 0 0 0 5 6

c =  NaN >> a = threshold2(4,z,y)

?? Error using ==> threshold2

Not enough output variables.

Be sure to properly comment your code.

From within 'hw4.m' write a series of expressions that demonstrate the threshold2 function being executed on at least three different sets of non-error generating input. Be sure to demonstrate the case when more ouput variables are present than corresponding input variables.

Finally, execute the threshold2 function with a threshold value plus three input variables but set it equal to only two output variables. Catch the error that your function should have generated such that the script doesn't stop executing and extract the message that was associated with that error. Use the display function to display the error message and then set all of the original output variables equal to NaN.

7.  Write a function called withdraw (in the file 'withdraw.m') that simulates withdrawing money from a bank account. The function takes a single input argument, a positive scaler double value. If the user passes a value that is not scaler or is not greater than 0, your function should throw an error.

The function should access a global variable called BALANCE. Subtract the amount of the withdrawal from the BALANCE variable. If the subtraction would take BALANCE to less than 0, leave BALANCE unchanged and throw an error. Also, if BALANCE is not yet defined, thow an error.

Finally you are limited to 5 withdrawals from your bank account. Use a persistent variable to store how many times the withdrawal function has been used. On the fifth and all subsequent calls to the function it should automatically throw an error and not perform the withdrawal.

The function should return only one value, the number of withdrawals remaining.

From the 'hw4.m' file set the global value BALANCE to some initial value. Then show some example calls to the withdraw function, followed by a display of the remaining value of BALANCE. You should demonstrate the various error conditions, but make sure to catch all errors and display the error message without forcing the script to terminate.

What you need to submit:

You need to submit these files:

·      hw4.m

·      prob1.m

·      prob2.m

·      prob3.m

·      triple.m

·      threshold1.m

·      threshold2.m

·      withdraw.m

Reference no: EM131104622

Questions Cloud

Discuss the use of arrays in java programs : Discussion Question: Discuss the use of arrays in Java programs versus the use of regular variables
Examples of information systems : 1. Using the example of a university, give examples of information systems for each of the four levels of scope shown in Figure 1 (Chapter 7). Describe three workgroup information systems that are likely to duplicate data. Explain how the characte..
Obtain a close approximation to the impact velocity v : Obtain a close approximation to the impact velocity v from the data given
Identify the augite minerals using the key provided : Identify the following minerals using the Key provided. Place the names with the appropriate number. Augite, Biotite, Calcite, Galena, Graphite, Gypsum, Halite, Hematite, Hornblende, Kaolinite, Microcline (Orthoclase), Muscovite, Plagioclase, Pyr..
Write a script m-file called hw4 : Write a script m-file called hw4.m. Label your solution to each exercise with a comment. Some of the exercises ask for additional script m-files that will be called from within hw4.m.
What circumstances are different types control statement use : Discussion Question: Under what circumstances are different types of Java control statements and loop types best utilized? Provide examples
Jurisdictional rules regarding liability : Should the jurisdictional rules governing use tax collection obligations be different from the jurisdictional rules regarding liability for income taxation? If so, in which context should the jurisdictional threshold be higher?
Leadership culture in the organization : As the new top-level executive of a medium-sized corporation, you have noticed that the leadership culture in the organization has been ineffective, which has lowered employee morale.
How do psychologists define personality : How do psychologists define personality - Provide an overview of the definition of personality.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write program to allow two users to play tic-tac-toe

Write a program that will allow two users to play tic-tac-toe. The program should ask for moves alternately from player X and player O.

  You will have to override some of the step-by-step procedure

Actually the author has not asked you to develop any new page here except that you will need to apply your external style sheet in your Index and Yurts pages done in Assignment 1A.

  Explain what can go wrong in resource management on c++

Explain What can go wrong in resource management on c++?

  Create ajax-based product catalog

Create an AJAX-based product catalog which obtains its data from JSON files located on the server. The data should be separated into four JSON files.

  How many credits they have taken in network systems

Write a program that will take in basic information from students, including their names and how many credits they have taken in Network Systems Administration program

  Create a multi-view program for the iphone

Compress the entire XCode project folder as a single zip, rar or other file format using an "archive file" or compression utility like PKZIP.

  Program instantiates four dates and allots invalid values

Demonstration program instantiates four Dates and purposely allots invalid values to some of arguments; class methods will correct invalid values.

  Create a utility procedure

Sum of Digits in a String. It is necessary to create a utility procedure that allows you to convert from a character to an integer value to allow you to sum the values of the digits in a string

  Code the next version of the cp1200 catering calculator

You are to plan and then code the next version of the CP1200 catering calculator, as described in the following information and sample output

  Draw a erd model a manufacturing company

Draw a ERD model A manufacturing company has several assembly plants in different cities. Each plant produces one product which requires certain parts in its assembly.

  Create script which checks day of the week

Create a script which checks day of the week, and takes one of two actions (step 2 or 3) depending on the day. If day is Monday through Friday, print (send to stdout) name of the day.

  Write a perl script code

Write a Perl script which uses the segment of code over and over again, and you are tired of repeatedly typing in this code. Which of the following must you do?

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