What steps would you take to solve this in Matlab? Write a function called next_prime that takes
Fantastic news! We've Found the answer you've been seeking!
Question:
What steps would you take to solve this in Matlab?
Transcribed Image Text:
Write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. Feel free to use the built-in isprime function to verify if the number is a prime or not. Here are some example runs: >> next_prime (2) ans = >> next_prime (8) ans = 3 >> next_prime (12345678) ans 11 12345701 Create a function file named next_prime.m that: Use a while loop to find the number k which is the smallest prime number that is greater than n. - In the script file, Class_21_App.m perform the following tasks: Ask user to input a scalar positive integer. Verify if the number is a positive number; if it is a scalar number; if it is an integer. If the number is not correct, display an error message. Call function next_prime to find the required prime number if the number that the user entered is valid. Use fprintf to display the prime number. Repeat the program until the user chooses to quit. For testing purposes please use the following inputs for the file you submit: Testing Conditions (1) -3; (2) 8.2; (3) [2 5 3]; (4) 2; (5) 12345678 Write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. Feel free to use the built-in isprime function to verify if the number is a prime or not. Here are some example runs: >> next_prime (2) ans = >> next_prime (8) ans = 3 >> next_prime (12345678) ans 11 12345701 Create a function file named next_prime.m that: Use a while loop to find the number k which is the smallest prime number that is greater than n. - In the script file, Class_21_App.m perform the following tasks: Ask user to input a scalar positive integer. Verify if the number is a positive number; if it is a scalar number; if it is an integer. If the number is not correct, display an error message. Call function next_prime to find the required prime number if the number that the user entered is valid. Use fprintf to display the prime number. Repeat the program until the user chooses to quit. For testing purposes please use the following inputs for the file you submit: Testing Conditions (1) -3; (2) 8.2; (3) [2 5 3]; (4) 2; (5) 12345678
Expert Answer:
Related Book For
Accounting Information Systems The Crossroads of Accounting & IT
ISBN: 978-0132991322
2nd Edition
Authors: Donna Kay, Ali Ovlia
Posted Date:
Students also viewed these databases questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
A 10.231-g sample of window cleaner containing ammonia was diluted with 39.466 g of water. Then 4.373 g of solution were titrated with 14.22 mL of 0.1063 M HCl to reach a bromocresol green end point....
-
Do you think a true transformational leader should ever lay off thousands of workers to help make a company profitable?
-
Figure 6-6 shows histograms of several binomial distributions with n = 6 trials. Match the given probability of success with the best graph. (a) p = 0.30 goes with graph _________. (b) p = 0.50 goes...
-
Split the National Football League data used in Problem 3.1 into estimation and prediction data sets. Evaluate the statistical properties of these two data sets. Develop a model from the estimation...
-
The following table shows the transactions experienced by J G Gutter Works (JGGW) during Year 7. The table contains missing data which are labeled with alphabetic characters (a) through (j). Assume...
-
The spreadsheet produces forecasted annual EPS of $7.08. Identify one forecasting assumption (which affects forecasted EPS) that could be different and explain the alternative assumption. Provide...
-
a. How many common shares are outstanding on each cash dividend date? b. What is the total dollar amount for each of the four cash dividends? c. What is the amount of the capitalization of retained...
-
Match List I of the nuclear processes with List II containing parent nucleus and one of the end products of each process and then select the correct answer using the codes given below the lists: List...
-
A simple pendulum consists of a \(1.00 \mathrm{~kg}\) bob on a string \(1.00 \mathrm{~m}\) long. During a time interval of \(27.0 \mathrm{~s}\), the maximum angle this pendulum makes with the...
-
You are aboard the International Space Station and are required to keep track of your mass because of your long stay in the free-fall conditions of deep space. To carry out this task, you hook a 215...
-
Two oscillatory motions are given by \(x(t)=A \sin (m \omega t)\) and \(y(t)=A \sin (n \omega t+\phi)\), where \(m\) and \(n\) are positive integers. Consider displaying these motions on a single...
-
Write a short commentary on each ledger account prepared in S1, to enable a nonaccountant to understand their purpose and content. Data from S1 Prepare ledger accounts to report the transactions and...
-
A tree that is \(32.6 \mathrm{~m}\) tall leans \(26.0^{\circ}\) from the vertical in the Farth reference frame. How tall is the tree, and at what angle does it lean, in the reference frame of a...
-
Prevlars budget for variable overhead and fixed overhead revealed the following information for an anticipated 41,600 hours of activity: variable overhead, $428,480; fixed overhead, $640,000. The...
-
If there is an unrealized holding gain on available-for-sale investments, it is reported as?
-
Discuss the obstacles an organization faces when it decides to implement a new enterprise system.
-
Discuss how business sales processes differ for an online furniture retailer and a brick-and-mortar furniture store.
-
Refer to the SAP Business One purchase order form shown in Figure 6.16. For each of the following database fields shown in the form, identify the database table in which the field is stored. a....
-
Some people argue that the government should not intervene in the case of a market failure because the government itself is inefficient and will simply create new problems to replace the ones it is...
-
Consider each of the following issues and discuss whether you support Theory X, Theory Y, neither theory, or some combination of them. Issue Theory X Theory Y Whether a person is healthy or sick...
-
Looking at Medicaids traditional eligibility rules, you will notice numerous value/policy judgmentspregnant women and children are favored over childless adults, the medically needy are favored over...
Study smarter with the SolutionInn App