Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

How to code question 4 and 5 on matlab ? Page of 8 0 - 20 4 L Prime Evaluation u nction result - prineCheck

How to code question 4 and 5 on matlab ?
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Page of 8 0 - 20 4 L Prime Evaluation u nction result - prineCheck (x) Input Type Description 1x1 double A positive integer Output Type Description result 1xN char A character array that is either "Non-Prime' or 'Prime' * Details You are required to write a recursive program that is able to evaluate if a positive integer xls a prime number. A prime number is defined as a positive integer that is not divisible without remainder by any integer except itself and 1. You are NOT ALLOWED to use the built-in MATLAB function isprime (). Your program should do the following: 1. Verify that x is a positive integer. 2. Evaluate if the integer x is a prime. 3. Display a message to the user if they used an invalid input using the MATLAB function disp. Tips Remember that 1 is not a prime number, and the only even prime number is 2. Tips Remember that 1 is not a prime number, and the only even prime number is 2. . Because your function has only one input and you are restricted to writing a program, the use of a persistent variable may be helpful to act as a potential divisor of If you use a persistent variable, clear it when your program concludes. This will help avoid computational mistakes the next time your function is called. 5 Prime Factorization I divisor function primefactors - primefactorization (x, divisor,primeFactors) Input Type Description x 1x1 double A n integer you wish to perform prime factorization on 1x1 double A possible positive divisor of x. primeFactors 1xM double An array of the current M prime factors of x. prime Factors is empty the first time your function is called. Output Type Description primeFactors 1xN double An array of all N prime factors of x. See details for an example. Details Prime factorization is the process of separating a composite number into its prime factors. You are to write a recursive function that accepts a positive integer x, a test divisor, and an array of the current prime factors. It should then output the prime factors of the integer x. For example, the prime factors of 72 are (2,2,2,3,3). You are required to do the following: 1. Stop the program if invalid inputs are used. 2. Verify that x is a positive integer greater than 1. 3. Verify that divisor is a positive integer in the range (1,7) 4. Perform the prime factorization of x. 5. The elements in your output array should increase from left to right. Tips Remember that I is not a prime number, and the only even prime number is 2. divisor acts similarly to the persistent variable in the primeCheck problem; however, in this case, it is an input of the function. If the recursion is implemented correctly, then primeFactors should already be sorted. . You might find the following algorithm and link to be useful. Prime Factor (N) U LUULISIUNI IU Implemented correctly, then primeFactors should already be sorted. You might find the following algorithm and link to be useful. Prime Factor (N) Input N> 0 2010 Kardi Teknomo Print N Printp

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions