Question

Can you explain this line by line, especially the for loop this function solve Ly = b for y Forwa...

Can you explain this line by line, especially the for loop
this function solve Ly = b for y

Forward solve a unit lower triangular system Ly = b for y

b = L @ y

def Lsolve(L, b):

  m, n = L.shape

assert m == n

assert np.all(np.tril(L) == L)

   assert np.all(np.diag(L) == 1)

y = b.astype(np.float64).copy()

for col in range(n):

  y[col+1:] -= y[col] * L[col+1:, col]

  return y

0 0
Add a comment Improve this question Transcribed image text
Answer #1

m, n = L.shape , so basically here getting the matrix size , after this assert m == n , here checking basically if this square matrix and if its not then show error , after this in next line (np.tril(L) == L) here checking basically if this lower triangular or something else and after this ,(np.diag(L) == 1), here checking that basically unit diagonal , after this basically in next line  copying b to y, in next line basically solving here if we say for each y's element , for equation see below 21 dr after solving y , return it.

Add a comment
Know the answer?
Add Answer to:
Can you explain this line by line, especially the for loop this function solve Ly = b for y Forwa...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Solve the system Ux = y for x. U = ? X = ? If the...

    Solve the system Ux = y for x. U = ? X = ? If the nxn matrix A can be expressed as A = LU, where L is a lower triangular matrix and U is an upper triangular matrix, then the system Ax = b can be expressed as LUX = b and can be solved in two steps: Step 1. Let Ux = y, so that LUX = b can be expressed as Ly = b. Solve this...

  • Function LUfac_solver.m is provided here: function [x] = LUfac_solver(LU,b,piv) % % function [x] = LUfac_solver(lu,b) %...

    Function LUfac_solver.m is provided here: function [x] = LUfac_solver(LU,b,piv) % % function [x] = LUfac_solver(lu,b) % % This program employs the LU factorization to solve the linear system Ax=b.   % % Input % LU: lu matrix from GEpivot_new function % b: right side column vector (ordered corresponding to original vector % sent to GEpivot_new) % piv: vector indicating the pivoting (row interchanges that took place % during GE % % Output % x: solution vector % % Written by Steve...

  • 2. Solve the linear system Ax = B, by, (20P) a) Finding LU-factorization of the coefficient...

    2. Solve the linear system Ax = B, by, (20P) a) Finding LU-factorization of the coefficient matrix A, b) Solving the lower triangular system Ly = b, c) Solving the upper triangular system Ux = y. where w A = 2 0 0 0 -2 1 0 2 0 0 0 0 - 1 1 1 4. -4 15 and b =

  • Using MATLAB please. Recall the formula for forward substitution to solve the lower triangular system 011...

    Using MATLAB please. Recall the formula for forward substitution to solve the lower triangular system 011 0 021 (122 ... 0 bi b2 0 ann be : anl an2 which is b; - ;=1 j=14; 1; i = 1,...n Write a M. "LAB function forward_substitution that solves a lower triangular system. Test your code using the example A= 2 0 0 1 1 0 2 3 b= 6 7 15 1

  • Write a function forward. m to solve n × n lower triangular systems and a func-...

    Write a function forward. m to solve n × n lower triangular systems and a func- tion backward.m to solve n x n upper triangular systems. Then write a function MYSOLVER.m to solve n × n systems (under the assumption that elimination can be performed without row exchanges). Use MYLU.m from last week's assignment. Test your code on Ax b with 3 2 45 8 4 5 213 19 13 15 A= 0-24 3 3 0 5 2 1 2...

  • use python and one loop to solve this problem Q6: Secondary Trace You are given a...

    use python and one loop to solve this problem Q6: Secondary Trace You are given a function that takes a square array, matrix, and returns the sum of the secondary diagonal values for matrix. This function employs a nested 2D for-loop. Write a function secondary trace single loop that solves the same problem using only one for-loop. For example, on the picture below secondary diagonal consists of values: a03, a12, a21, a30. a00 a01 a02 a03 a10 all a12 a13...

  • can you calculate and explain why? thanks (a) A triangular loop with an area of 4 m2, positioned in the x-y plane, i...

    can you calculate and explain why? thanks (a) A triangular loop with an area of 4 m2, positioned in the x-y plane, is situated in air in a time-varying magnetic field, as shown in Figure 2. The loop includes a resistor of 10 Ω. The magnetic flux density B is given as t+1 6) Determine the induced emf (electromotive force) in the triangular loop. (Gi) Determine the induced current in the triangular loop, assuming that the wire resistance is negligible....

  • Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST b...

    Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST be written as specified. In your main code test all of the specified functions. Each function must have a comment block explaining what it does, what the parameters are and what the return value is. Please remember the following two guidelines: unless the purpose of the function is to generate output DO NOT write to the screen within the function unless the purpose...

  • A2. (a) Explain how the open-loop polar plot can be used to assess closed-loop stability by...

    A2. (a) Explain how the open-loop polar plot can be used to assess closed-loop stability by applying Nyquist's stability criterion. Apply Nyquist's stability criterion to determine the stability condition for a closed-loop system that is unstable in the open-loop. [30%] = K (b) An unstable system has transfer function given by G(S) in which the gain K is S(S-2) positive. A derivative compensator H(s) = 0.5s + 1 is inserted in the negative feedback path to form a control loop....

  • Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we...

    Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we considered converting a byte string to decimal. What about converting a binary string of arbitrary length to decimal? Given a binary string of an arbitrarily length k, bk-1....bi .box the decimal number can be computed by the formula 20 .bo +21.b, + ... + 2k-1. bx-1- In mathematics, we use the summation notation to write the above formula: k- 2.b; i=0) In a program,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT