(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

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