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 selector is used to match any element in the hierarchy

The  selector is used to match any element in the hierarchy.

  Different organizational software design projects

With an understanding of the existing requirements review process, expected software design models, the software solution design, expected software specifications, and the requirements for the new software design project selected, you must now add..

  String s of lowercase english letters

Given a string S of lowercase English letters, write a program to find the longest magic string than can be obtained by removing some letters of S. If there are more than one solutions, choose the longest magic string which is lexicographically small..

  Calculate the expected value for lottery game

Calculate the expected value for this game. Interpret what it means. Do not forget that you initially lose $1 by buying a ticket.

  Calculate the branch prediction accuracy of various

As a computer architect it is your job to calculate the branch prediction accuracy of various schemes to evaluate which is the best branch predictor i.e the one with the highest accuracy. Given the following branch patterns,(a) NT,T,NT,T,NT (b) T,T,N..

  Development of an hr system

Define the business requirements for the development of an HR system to support the objective of this request. Create a detailed system design and a project implementation plan required to complete the project.

  Write a program that reads in two floating-point numbers and

Write a program that reads in two floating-point numbers and tests whether they are the same up to two decimal places. here are two sample runs.

  Distinguish distances that moved their shopping carts

Performing 200 Nm of work. Both Brian and Dawn are exerting same amount of force (20 N). Distinguish the distances that Brian and Dawn moved their shopping carts.

  Have no hesitation buying over the internet

List some items you would have no hesitation buying over the Internet, some items you might want to think about a bit before buying and some items you would never consider buying over the Internet. Justify you reasons in each case.

  Explain how you can extend the sci capability

Explain how you can extend the SCI capability to RF and Bluetooth communication - Imagine an RFID device connected to SCI0 that sends a 16 character code to the DB-12 board when an item is swiped

  Compute and display the average age

Create a Class StudentType Create a StudentType array of 50 students Set the age of the first student to 10, second student to 11, and so on until the last student to 59. Compute and display the average age of all 50 students with the help of a fu..

  Circuit that has 5 slide switches as inputs

Design and code a circuit that has 5 slide switches as inputs and a push-button. When the button is pressed, the circuit will drive a stepper motor n-steps in the clockwise direction

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