Write an m file that defines a row vector

Assignment Help Basic Computer Science
Reference no: EM13834974

  1. Write an M-file that defines a row vector of 50 elements with all ones.

  2. Add a code that replaces every element that is in an even place (for example the 2nd, 4th, 6th,...) with the number 2.

  3. Add a code that replaces every element that is in a place divisible by three (for example the 3rd, 6th, 9th,...) with the number 3.

  4. Turn in a printout of the final M-file and the output after running Parts (a) through (c).

  5. Write a function file in MATLAB that takes in one input and returns a single output. Call the function getSquared. The function should output the square of the number that it takes as input. Remember that the function must actually RETURN the squared value, and not simply display it on screen. Save the function file in some directory that you created. Turn in a printout of the function file.

  6. Write a script M-file called testSquared.m that defines a variable called xinput. Give any numerical value to xinput. From within this M-file, call the function getSquared. Store the output from the function file in a new variable called xoutput. Write a statement in the M-file that will print both the xinput and xoutput on the screen. Save the script M-file in the same folder as the function file. Turn in a printout of the M-file.

  7. Run the file testSquared.m from the command prompt. Turn in a printout of th output you get.

  8. Run the function file getSquared.m from the command prompt to calculate the square of any variable in your workspace. If you do not have one, create it in th workspace. Turn in a printout of your command prompt output.

  9. Save your getSquared.m function as getSquaredSpecial.m. Modify this function. Add a test code in your new function to determine whether the input number is greater than or equal to zero. If yes, then the function does exactly what it did before (that is, squaring). If not, then the function simply returns the value -1. Turn in a printout of your getSquaredSpecial.m file.

  10. In a similar fashion as above, create the function testSquaredSpecial.m file. Run two cases: (i) xinput is a positive number, and (ii) xinput is a negative number. Turn in a printout of the command prompt output for both cases.

  11. Write a function called sumHundred that takes an integer as the input. The function should determine whether the input is an integer between 1 and 100. If not, the function should display an appropriate error message. Turn in a printout of the function file.

  12. Test the function from the command prompt using (i) a number between 1 and 100, and (ii) a number greater than hundred. Turn in a printout of the command prompt output for both cases.

  13. You will now modify your function sumHundred. Add some logic to it using for or while loops, such that the function evaluates the sum of all integers from 1 to the input number. For instance, if the input number is 79, it should evaluate the sum of the first 79 integers. Do not use any built-in MATLAB functions. Turn in a printout of the modified function file. Run two test cases from the command prompt and turn in a printout of the results along with the M-file.

  14. Save your sumHundred function as sumEvenHundred. Add another logic code to the original function, such that now it evaluates the sum of all even integers from 1 to the input number. For instance, if the input number is 51, it should evaluate the sum of the even integers between 1 and 51. Turn in a printout of th function file and run it for two test cases from the command prompt. Turn in a printout of the results.

  15. Write a function called hiddenSum that takes two inputs and returns the sum of the two inputs. Turn in a printout of the function.

  16. Write a script M-file called testHiddenSum.m that defines two variables x and y Assign some values to these variables. Call the function hiddenSum from within this script M-file and store the result in a local variable, z. Run the script M-file and turn in a printout with the value of z.

  17. Modify the function hiddenSum such that now it DOES NOT HAVE any output arguments. Now modify your script M-file such that it calls hiddenSum using x and y as inputs and assigns the result to the variable z. You will need to further modify your function file. Submit a printout of the new function and script files and command prompt results from running your script M-file.

  18. Now modify your function hiddenSum such that it DOES NOT HAVE any input OR output arguments. Modify your script M-file such that it calls hiddenSum using x and y as inputs, and stores the result in the variable z. You will need to further modify your function file. Submit a printout of the new function and script files, and the command prompt results from running your script M-file.

Reference no: EM13834974

Questions Cloud

What is the pretax required return on gordons stock : The Gecko Company and the Gordon Company are two firms whose business risk is the same but that have different dividend policies. Gecko pays no dividend, whereas Gordon has an expected dividend yield of 2 percent. What is the pretax required return o..
Explain the basics of the countrys culture : Explain the basics of the countrys culture
What is the value of the firms operations : Young's free cash flow during the just-ended year (t=0) was $100 million, and FCF is expected to grow at a constant rate of 5% in the future. If the weighted average cost of capital is 15%, what is the value of the firm's operations?
How can these systems affect employee motivation : How do the physiological, psychological, and social needs described in the textbook influence workplace reward systems? How can these systems affect employee motivation
Write an m file that defines a row vector : Write an M-file that defines a row vector of 50 elements with all ones. Add a code that replaces every element that is in an even place (for example the 2nd, 4th, 6th,...) with the number 2. Add a code that replaces every element that is in a place d..
Sales and projections indicate a return on invested capital : The SignPost has a WACC of 12%. They are contemplating growing their sales and projections indicate a return on invested capital (ROIC) of 9.5% as a result of the sales growth. The growth in sales: a) destroys value, b) adds value c) cannot be determ..
Calculate tax equivalent rate of return-marginal tax rate : A municipal bond you are considering as an investment currently pays a 6.81 percent annual rate of return. Calculate the tax equivalent rate of return if your marginal tax rate is 28 percent. Calculate the tax equivalent rate of return if your margin..
Introduction to the activity : In 1996 history was made when a sheep named Dolly was the first animal to be successfully cloned (Wilmut et al. 1997). Since then there have been numerous advancements in the science of cloning, resulting in the development of other clones from horse..
Describe high performance workplace practices : Employers do appear to compensate at least some of their workers for engaging in high performance workplace practices. There is a significant associatiion between high performance workplace practices and increased wage inequality.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  The availability and multitude of forensic toolkits

the availability and multitude of forensic toolkits continue to increase. the last decade has witnessed the emergence

  Strayer library to research articles on ethical issues

You may also use the Internet or the Strayer Library to research articles on ethical issues in information systems and choose one (1) ethics issue of interest to you.

  Given two variables is_empty which is associated with a bool

Given two variables is_empty which is associated with a bool

  Explores the performance consequences

This problem explores the performance consequences of having only a single level of cache in a modern processor with 40 ns DRAM column access time and a clock period of 400 ps (clock frequency 2.5 GHz). You are given the following data: A particul..

  New technologies have created new capabilities

New technologies have created new capabilities, including access, capture, speed, and permanence. Technology often has a more wide-ranging effect than the purpose for which it is chosen. As a result, advances in technology present both opportu..

  Explain decision support systems

Decision support systems: Modeling and Analysis question - Why are models not used in industry as frequently as they should or could be?

  Select and describe in detail the evaluation method

Computer class written assignment. select and describe in detail the evaluation method that you plan to use to compare and contrast the 3 options. Write 250 to 300 words.

  Full description of the new system

Full description of the new system, a description of its components, and the benefit it will provide to Riordan

  Type of distribution students like to see to earn good grade

What type of distribution would the students like to see in order to be most likely to earn a good grade? Explain your answers.

  You are given for input the student name

Draw a flowchart to illustrate the following problem. You are given for input the student name, number of credits, and cost per credit. You need to output the student name, number of credits and total tuition.

  Determine whether a string is in the language l

Write a pseudocode function that uses a stack to determine whether a string is in the language L, where a. L= {w : w contains equal numbers of A's and B"s} b. L = {w : is of the form A(n) B(n) for some n >/= 0}

  Show the design of a modulo 7 asynchronous counter

Using positive edge triggered flip flops, show the design of a modulo 7 asynchronous counter that counts: 7,6...1,7, etc. You may assume that your flip flops have asynchronous Set and Reset inputs available. (Hint: Connect Q to the clock input of the..

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