{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

I- Computer QuestionsExam 1

I- Computer QuestionsExam 1 - Computer Question 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Question 1: Calculating the Value of a Function f(x) = 4e x+2 for -6 <= x < -2 x 2 for -2 <= x < 2 (x+62) 1/3 for 2 <= x <= 6 Write Matlab code that asks the user to enter x, and then displays the value of f(x) for that x. If the user enters a value that is outside of the domain of this function (i.e. x is not between -6 and 6), your code should instead display “Error” Computer Question 2: Sum of Composites Run the following commands, which create a 100 element matrix B : rand( 'state' , 4 ) ; B = round( 120*rand(10,10) - 10 ); Write Matlab code that calculates the sum of all of the numbers in B after eliminating the following numbers: a) Those that are prime numbers b) Those that are less than 0 or greater than 100 Display the following statement using fprintf, substituting in the values you find: "The product of all composite numbers in B between 0 and 100, inclusive, is ___" You cannot use loops in any part of your answer this question; you must use matrix / vector operations and functions. The correct answer to this problem is 3405 if you do it correctly.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}