(Euclidean Algorithm) As mentioned in class, the Euclidean algorithm is useful for finding the GCD of two numbers A and B by producing the sequence R, by R1 = mod (A, B), R2 = mod (B, Ry), R, = mod (R„ 2, Rµ 1) for n > 2. The last non-zero number in the sequence is the GCD of A and B. euclid_gcd Function: Input variables: • a scalar representing A • a scalar representing B (which you may assume is not equal to A) Output variables: • a scalar representing the GCD of A and B • a vector of all iterates produced (this vector should include R1 and R2 as its first entries as well as the final zero entry) A possible sample case is: » [GCD, R] = euclid_gcd(32, 40) GCD = 8 R = 32 8 0 » [GCD, R] = euclid_gcd(100, 65) GCD = 5 R = 35 30 5 0

Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Question

make mathlab code 

**Euclidean Algorithm**

The Euclidean algorithm is useful for finding the GCD (greatest common divisor) of two numbers \( A \) and \( B \) by producing the sequence \( R_n \) as follows:

- \( R_1 = \text{mod} (A, B) \)
- \( R_2 = \text{mod} (B, R_1) \)
- \( R_n = \text{mod} (R_{n-2}, R_{n-1}) \), for \( n \ge 2 \).

The last non-zero number in the sequence is the GCD of \( A \) and \( B \).

**euclid_gcd Function:**

- **Input variables:**
  - A scalar representing \( A \).
  - A scalar representing \( B \) (which you may assume is not equal to \( A \)).

- **Output variables:**
  - A scalar representing the GCD of \( A \) and \( B \).
  - A vector of all iterates produced (this vector should include \( R_1 \) and \( R_2 \) as its first entries as well as the final zero entry).

**Sample Cases:**

1. **Case 1:**
   ```
   >> [GCD, R] = euclid_gcd(32, 40)
   GCD = 8
   R =
   32  8  0
   ```

2. **Case 2:**
   ```
   >> [GCD, R] = euclid_gcd(100, 65)
   GCD = 5
   R =
   35  30  5  0
   ```
Transcribed Image Text:**Euclidean Algorithm** The Euclidean algorithm is useful for finding the GCD (greatest common divisor) of two numbers \( A \) and \( B \) by producing the sequence \( R_n \) as follows: - \( R_1 = \text{mod} (A, B) \) - \( R_2 = \text{mod} (B, R_1) \) - \( R_n = \text{mod} (R_{n-2}, R_{n-1}) \), for \( n \ge 2 \). The last non-zero number in the sequence is the GCD of \( A \) and \( B \). **euclid_gcd Function:** - **Input variables:** - A scalar representing \( A \). - A scalar representing \( B \) (which you may assume is not equal to \( A \)). - **Output variables:** - A scalar representing the GCD of \( A \) and \( B \). - A vector of all iterates produced (this vector should include \( R_1 \) and \( R_2 \) as its first entries as well as the final zero entry). **Sample Cases:** 1. **Case 1:** ``` >> [GCD, R] = euclid_gcd(32, 40) GCD = 8 R = 32 8 0 ``` 2. **Case 2:** ``` >> [GCD, R] = euclid_gcd(100, 65) GCD = 5 R = 35 30 5 0 ```
Expert Solution
Reqiured matlab code

Advanced Math homework question answer, step 1, image 1

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Advanced Engineering Mathematics
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Mathematics For Machine Technology
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,
Basic Technical Mathematics
Basic Technical Mathematics
Advanced Math
ISBN:
9780134437705
Author:
Washington
Publisher:
PEARSON
Topology
Topology
Advanced Math
ISBN:
9780134689517
Author:
Munkres, James R.
Publisher:
Pearson,