Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

  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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91404809

Have any Question?


Related Questions in Computer Engineering

On a single diagram illustrate the following using the uml

On a single diagram, illustrate the following using the UML notation for objects, links and messages. (a) An object of class Window, with no attributes shown; (b) An object of class Rectangle with attributes length and w ...

Suppose two packets arrive to two different input ports of

Suppose two packets arrive to two different input ports of a router at exactly the same time. Also suppose there are no other packets anywhere in the router. a. Suppose the two packets are to be forwarded to two differen ...

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Research the fire at the federal aviation administration

Research the fire at the Federal Aviation Administration (FAA) facility in Chicago, Illinois (2014). Provide insight into the following: What went wrong? What went right? Would a risk assessment strategy if employed miti ...

Question need a discussion post of 500-700 words in apa

Question: Need a discussion post of 500-700 words in APA format with 4 references & citations. Only For Dr. Silvercoast Layout and Flows In the book Operations Research, (Nigel Slack et al. 192), layout refers to the arr ...

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Question several social networks like facebook or linkedin

Question : Several social networks like Facebook or LinkedIn are able to accurately recommend people you may want to become friends with or connect to. Explain what graph algorithm is relevant for producing this kind of ...

Question you are shopping for a new computer you will be

Question: You are shopping for a new computer. You will be using the computer for everything you do, such as school, socializing, gaming, and communicating. Your total budget before tax is $1,000.00. Considerations: • Bu ...

Question specify design implement im c a class for a card

Question : Specify, design implement im c++ a class for a card in a deck of playing cards. The object should contain methods for setting and retrieving the suit and rank of the card. Make sure to separate your work on s ...

Question research and discuss the html document object

Question : Research and discuss the HTML Document Object Model (DOM). Discuss how it can be manipulated via JavaScript to provide dynamic web page behavior. Explain in detail give some examples .

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As