Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello. I NEED A PYTHON CODE. I have this python code (bellow) and I need to solv

ID: 3856117 • Letter: H

Question

Hello. I NEED A PYTHON CODE. I have this python code (bellow) and I need to solve, still in python, the linear systems Va = y and Vb= y using algorithms created by factorization. 1. LU with and without pivoting, 2. by the polar decomposition of A and 3. QR with and without pivoting.

import random import numpy as np k = 2 # number of equally spaced elements space = 0.3 #value of the spacing between equally spaced elements x = [i"space for i in range(k)] #equally spaced xk elements for i in range(k,6): x.append(-1l+random.random0 ) #randomly spaced rest of the elements y = [np.exp(i) for i imx] #np.sinO, np.cos(), np.expl, np.log0, np.log100, np.logo can be used V = np.vander(x) #constructs vandermonde matrix of the vector X. U = np.vander(y) #constructs vandermonde matrix of the vector 'y.

Explanation / Answer

/* method to return prime divisor for n */

long long int PollardRho(long long int n)

{

    /* initialize random seed */

    srand (time(NULL));

    /* no prime divisor for 1 */

    if (n==1) return n;

    /* even number means one of the divisors is 2 */

    if (n % 2 == 0) return 2;

    /* we will pick from the range [2, N) */

    long long int x = (rand()%(n-2))+2;

    long long int y = x;

    /* the constant in f(x).

     * Algorithm can be re-run with a different c

     * if it throws failure for a composite. */

    long long int c = (rand()%(n-1))+1;

    /* Initialize candidate divisor (or result) */

    long long int d = 1;

    /* until the prime factor isn't obtained.

       If n is prime, return n */

    while (d==1)

    {

        /* Tortoise Move: x(i+1) = f(x(i)) */

        x = (modular_pow(x, 2, n) + c + n)%n;

        /* Hare Move: y(i+1) = f(f(y(i))) */

        y = (modular_pow(y, 2, n) + c + n)%n;

        y = (modular_pow(y, 2, n) + c + n)%n;

        /* check gcd of |x-y| and n */

        d = __gcd(abs(x-y), n);

        /* retry if the algorithm fails to find prime factor

         * with chosen x and c */

        if (d==n) return PollardRho(n);

    }

    return d;

}

/* driver function */

int main()

{

    long long int n = 10967535067;

    printf("One of the divisors for %lld is %lld.",

          n, PollardRho(n));

    return 0;

}