Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Use Matlab. No Conditionals, loops, and iterations. Inputs: 1. (double) The maximum value to test Outputs: 1. (double) A vector of all primes smaller

Please Use Matlab. No Conditionals, loops, and iterations.

Inputs:

1. (double) The maximum value to test

Outputs:

1. (double) A vector of all primes smaller than the input.

Banned Functions:

primes(), isprime(), factor(), setdiff(), intersect(), ismember()

The definition of a prime number is a number whose only factors are 1 and itself. As a result the way we can identify a prime is to test if it is divisible by any numbers less than it. Mathematicians have come up with a neat trick to optimize this process: In order to determine if a number is prime it must not be evenly divisible by any positive integer which is less than its square root (rounded up), except 1.

Function Description:

Given a maximum value to test, return all prime numbers less than or equal to that value.

Example:

p = primesOfGreece(10);

p [2, 3, 5, 7]

Notes:

Think about how you can create a matrix to help you determine what numbers are prime. Use either the repmat() function or on how both the .* and ./ operators work when

given a row vector and a column vector (e.g. 1:10 .* 1:4').

1 is not a prime number.

The input will always be a positive integer greater than 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions