Write a function in Matlab which takes as input an integer x and as output returns the biggest prime number that is less than or equal to x. For example, if the input is 7, the output would be 7. If the input is 40, the output would be 37. (Reminder: isprime.)

Answers

Answer 1
Answer:

Answer:

Explanation:

The objective is to write a Matlab function getPrime()

CODE:

function prime = getPrime(x) %function definition for getPrime which receives x as input and returns prime.

   while (x >= 1) % loop until x is zero.

       if isprime(x) % matlab built-in function to check if x is a prime number.

           prime = x; % assign x to prime.

           break % break out of loop. we got the prime number value in variable prime.

       end

       x = x - 1; % when x is not prime, x is decremented by 1 and loop continues.

   end

end

prime = getPrime(12); % passes 12 to function.

disp(prime) % display value in prime. 11 is the output since it is the biggest prime number below 12.


Related Questions

Initialize a list. ACTIVITY Initialize the list short.names with strings 'Gus', Bob, and 'Ann'. Sample output for the given program Gus Bob Ann 1 short_names- Your solution goes here 2 # print names 4 print(short_names[0])
Write an algorithm that gets as input your current credit card balance, the total dollar amount of new purchases, and the total dollar amount of all payments. The algorithm computes the new balance, which this time includes an 8% interest charge on any unpaid balance below $100 , 12% interest on any unpaid balance between $100 and $500, inclusive, and 16% on any unpaid balance about $500.
A computer professional who has access to sensitive information shares this information with a third party. Which professional code of conduct did the person violate? A. diligence in service B. company discipline norms C. confidentiality of information D. conflict of interest
The following JavaScript program is supposed to print: 1 by 4 by 9on a single line by itself. Unfortunately the program contains at least eight mistakes. Write the corrected line beside the line in error.var N; // TextN := 1;document.writeln( N );document.writeln( “ by “);document.writeln( “N + 3”);document.writeln( “ by “ );document.writeln( N + 5);
Suppose an array with six rows and eight columns is stored in row major order starting at address 20 (base 10). If each entry in the array requires only one memory cell, what is the address of the entry in the third row and fourth column?

Write out the base sequence that is added directly after the primer. In order for Moodle to correctly grade this question, write only the letters representing the bases, write your answer in 5' to 3' direction, and do not have any spaces between the letters and do not label the 5' and 3' ends.

Answers

Answer:

see explaination

Explanation:

please kindly see attachment for the step by step solution of the given problem.

A computer processor stores numbers using a base of: _____.a) 2b) 10c) 8d) 16

Answers

A computer processor stores numbers using a base of 16. The correct option is d).

What is a computer processor?

A computer processor is a computer processing unit that is a CPU. CPU controls all the functions of the computer. It stores memory, and it has two types of memory. Short-term and long-term. It executes all the instructions given to the computer.

The design expert discusses the project three-dimensionally at this point in the process. To define the character of the finished project and an ideal fulfillment of the project program, a variety of potential design concepts are investigated.

The different kinds of computer processors are: microprocessor, microcontroller, embedded processor, digital signal processor

Therefore, the correct option is d). 16.

To learn more about computer processors, refer to the link:

brainly.com/question/15102947

#SPJ5

It stores a base of 16

For each of the following algorithms medicate their worst-case running time complexity using Big-Oh notation, and give a brief (3-4 sentences each) summary of the worst-case running time analysis. (a) Construction of a heap of size n , where the keys are not known in advance.
(b) Selection-sort on a sequence of size n.
(c) Merge-sort on a sequence of size n.
(d) Radix sort on a sequence of n integer keys, each in the range of[ 0, (n^3) -1]
(e) Find an element in a red-black tree that has n distinct keys.

Answers

Answer:

Answers explained below

Explanation:

(a) Construction of a heap of size n , where the keys are not known in advance.

Worst Case Time complexity - O(n log n)

Two procedures - build heap, heapify

Build_heap takes O(n) time and heapify takes O(log n) time. Every time when an element is inserted into the heap, it calls heapify procedure.

=> O(n log n)

(b) Selection-sort on a sequence of size n.

Worst Case Time complexity - O(n^2)

Selection sort finds smallest element in an array repeatedly. So in every iteration it picks the minimum element by comparing it with the other unsorted elements in the array.

=> O(n^2)

(c) Merge-sort on a sequence of size n.

Worst Case Time complexity - O(n log n)

Merge sort has two parts - divide and conquer. First the array is divided (takes O(1) time) into two halves and recursively each half is sorted (takes O(log n) time). Then both halves are combines (takes O(n) time).

=> O(n log n)

(d) Radix sort on a sequence of n integer keys, each in the range of[ 0 , (n^3) -1]

Worst Case Time complexity - O (n log b (a))

b - base of the number system, a - largest number in that range, n - elements in array

Radix sort is based on the number of digits present in an element of an array A. If it has 'd' digits, then it'll loop d times.

(e) Find an element in a red-black tree that has n distinct keys.

Worst Case Time complexity - O (log n)

Red-black tree is a self-balancing binary tree => The time taken to insert, delete, search an element in this tree will always be with respect to its height.

=> O(log n)

Look at the following assignment statements:word1 = "skate"
word2 = "board"

What is the correct way to concatenate the strings?


newWord = word1 / word2
newWord = word1 + word2
newWord = word1 * word2
newWord = word1 = word2

Answers

The correct way to concatenate the strings is:

newWord = word1 + word2

Answer:

newWord = word1 + word2

Explanation:

Cloud storage refers to the storage of data on ______.a. your mobile device.b. your desktop computer.c. an external drive.d. a server on the Interne.

Answers

The correct answer is:

Cloud storage refers to the storage of data on a server on the internet.

Every organization relies on data, In our daily job, we all make use of a huge amount of data(either in gigabytes or terabytes). And if you have a lot of files on your computer, it's probable that your computer may lose momentum and slow down, resulting in bad performance. While there are several external storage options available for storing and backing up your data, these devices are not infallible. Any incident, such as theft, or damage, might result in the loss of vital data.

This is where Cloud Storage comes into play. Cloud storage is a handy and dependable method of storing and retrieving information on the internet.

It is a cloud computing system in which data is stored on the server-side of the Internet and is managed and operated by a cloud computing provider. 

Therefore, from the above explanation, we can conclude that the correct Option is D

Learn more about Cloud Storage here:

brainly.com/question/23073532?referrer=searchResults

Answer:

D.  server on the internet

Explanation:

Write a loop that counts the number of space characters in a string. Recall that the space character is represented as ' '.

Answers

Answer:

I am writing Python program.

string = input("Enter a string: ")

print(string.count(' '))

Explanation:

The first statement takes input string from the user.

input() is used to read the input from the user.

The next statement uses count() function to count the number of times the specified object which is space ' ' hereoccurs in the string.

The print() function is used to return the number of times the space occurs in the string entered by the user.

Output:

Enter a string: How are you doing today?

4

The screenshot of program and its output is attached.