Write a matlab function

Assignment Help MATLAB Programming
Reference no: EM131720126

Question 1. Let A = LU be a LU-factorisation of a NxN matrix A into a product of a lower-triangular matrix L and a upper-triangular matrix U. The solution x = U-1L-1b of Ax = b can be found efficiently by a "forward substitution" followed by a "backward substitution" using the following formulas derived in section §4.3.2 of the Lecture Notes

[L-1b]i = zi = (bi - j=1i-1lijzj ) 1/lii, for i = 1, 2....., N,

[U-1L-1b] = xi = (zi - j=i+1N uijxj ) 1/uii, for i = N, N-1, ....., 1,

Matlab code for forward substitution (1) is provided in Listing 1. Observe how elements of b that are no longer needed are replaced. Write a Matlab function b = backsolve(U,b) to perform backward substitution.

Listing 1: Matlab function implementing equation (1) for the solution of a lower-triangular system by forward substitution.

function b = for wardsolve (L, b)

[N , N ] = size(L);

b (1)= b (1)/ L (1 ,1);

for i = 2: N

b (i) = ( b ( i) - L (i ,1: i -1)* b (1: i -1))/ L (i , i );

end

Question 2. Let A = LU be a LU-factorisation of a given N × N matrix A into a product of a unit-lower-triangular matrix L with lii = 1 and a upper-triangular matrix U, to be determined. Show that the elements of U and L are given by

uij = (aij - k=1i-1likukj ), for i = 1, 2,..... j,     (3)

lij = (aij - k=1j-1likukj )1/ujj, for i = j + 1, j + 2,..... ,N,     (4)

for every j = 1, 2, ...., N .

[HINTS: Start from the explicit expression for matrix multiplication. Take into account the location of zeroes in L and U . May be useful to do Question 3 below before you do Question 2.]

Question 3. Illustrate the usage of equations (3) and (4) and find the LU-factorisation of the square matrix

1980_Matrix.jpg

[HINTS: Follow Example 4.29 from the Lecture Notes but proceed column-by-column rather than crosswise.]

Observe the following.

1. The u's and l's that occur in the right-hand side of (3) and (4) are already determined by the time they are needed. This makes the method possible and efficient.

2. The a's corresponding to u's and l's that are already determined are never needed again. This allows to overwrite the matrix A which is useful for pivoting, see below, and for reducing computer memory requirements.

3. Equation (3) in the case of i = j (its final application) is exactly the same as equation (4) except for the division in the latter equation; in both cases the upper limit of the sum is k = j - 1(= i - 1). This fact allows to incorporate partial pivoting (to select a large by modulus pivot (diagonal element ujj) for the division in (4)), which is essential for the method to work. Practically, compute l'ij = (aij - j-1Σk=1 likukj), swap
the rows of A (which you have been overwriting with L and U ) corresponding to ujj and m = max {|ujj|,|l'j +1,j|, |l'j +2j|,....|l'N,j| and only then divide by the pivot m to fully implement equation (4). Keep a permutation matrix P as you are now actually factorising PA = LU, instead.

Question 4. Write a Matlab function [P,L,U] = ColumnCroutLU(A) to perform the column- wise Crout method given by equations (3) and (4), overwriting the matrix A and performing partial pivoting as described in Question 3. Your function must take as a single argument the square matrix A and return a permutation matrix P, a unit-lower-triangular matrix L and upper-triangular matrix U of the same size. A Matlab function to perform one pivoting row swap is given in Listing2.

Use your ColumnCroutLU to factorise the matrices,

772_Matrix1.jpg

switching pivoting on and off. Verify that your factorisations satisfy PA = LU.

[HINTS: The code of Listing1can serve as an example. The inbuilt Matlab functions tril and triu can be used to extract L and U from the overwritten A.]

Listing 2: Matlab function to perform one pivoting row swap. Takes as arguments a matrix A to be pivoted and a pivot position (j,j) and returns a permutation matrix P and a modified A.

function[P , A ] = ppivot (A , j) [N , N ] =size( A );
P =eye( N );
[ amax , s] =max(abs( A ( j:N , j ))); s = s+ j -1;
A ([ j , s ] ,:) = A ([ s , j ] ,:);
P ([ j , s ] ,:) = P ([ s , j ] ,:);
end

Question 5. Study and run the Matlab function MysteriousCode provided in Listing3. What problem does it solve? Explain the related theory. Explain and comment the given code.

Listing 3: A Matlab function that performs a mysterious computation all the while using your own functions written for Questions 1 and 4.

function MysteriousCode
x = [0:1:10]';
y = cos( x );
A =vander( x );
[P ,L , U ]= ColumnCroutLU(A);
checkfact = L*U - P*A
z = forwardsolve (L, P * y );
a= backsolve (U, z );
xx = [0:0.1:10] ' ;
B = vander( xx );
BB = B (: ,end-10:end);
yy = BB * a; zz = cos( xx );
err =abs( zz - yy );
figure; plot(x ,y ,'-o');
hold on;plot( xx , yy ,'r');hold on;
figure;plot( xx , err );
end

Verified Expert

This problem is related to LU-factorization and Column-wise Crout method with partial pivoting. To solve the linear equation, It can be useful. The report has been prepared in latex and MATLAB program is also included for learning programming.

Reference no: EM131720126

Questions Cloud

Ambiguity fallacy-statue of liberty is composed of molecules : Molecules are in constant random motion. The Statue of Liberty is composed of molecules. Therefore, the Statue of Liberty is in constant random motion.
What is the minimum score needed to be in the top : Suppose that scores on a particular test are normally distributed with a mean of 110 and a standard deviation of 16. What is the minimum score
Reference to employee rights and policies and procedures : In your experience, how do managers cope with demands, constraints, and choices confronting them with reference to employee rights and policies and procedures?
Discuss about civil liability : Discuss the incidence, expense, and benefits of lawsuits against the police and their ability to prevent or not prevent our nation
Write a matlab function : Write a Matlab function [P,L,U] = ColumnCroutLU(A) to perform the column- wise Crout method given by equations (3) and (4), overwriting the matrix
Examine the critical competitive moves that htc made : examine the critical competitive moves that HTC made. From the case study, examine the actions that HTC took in order to compete against Apple.
Passengers booked for a certain flight : From experience, an airline knows that only 75% of the passengers booked for a certain flight actually show up. If 7 passengers are randomly selected
Leadership styles influence the organizational culture : How will their personal leadership styles influence the organizational culture?
Discuss boot camps versus regular incarceration : They types of offenders who are sentences to boot camps, The effectiveness of boot camps versus regular incarceration

Reviews

inf1720126

1/2/2018 4:48:21 AM

Please find the the solutions of assignment 1 in the attached file. There is no different between the tutor's solutions & professor of subject. Your figures provided are correct. LATEX was a big issue but you guys solved it in latex Now I am very happy with your work and i will provide the next assignment to you soon.

len1720126

11/13/2017 5:04:33 AM

This is a new assignment in applied maths and it does require much knowledge and programming by MATLAB. We really need an excellent expert in both MATLAB program and Mathematics. Please let me how much you need to do it perfectly. Study and run the Matlab function MysteriousCode provided in Listing3. What problem does it solve?

Write a Review

MATLAB Programming Questions & Answers

  Develop matlab function for the fixed-point method

Develop your own Matlab function for the Fixed-point method. Use the estimated relative error as your stopping criterion. The first line of your function should be function

  Display the magnitude of images two-d fourier transform

Display the magnitude of its 2-D Fourier Transform in the form of the image. Bring the (0, 0) - frequency coordinate to the center of this display.

  The matlab language has the built-in ability

The MATLAB language has the built-in ability to perform mathematical operations on complex numbers. However there are times when it is useful to treat complex numbers as structures.

  Draw the set x on a two-dimensional plane

Draw the set X on a two-dimensional plane and draw the set Yon a two-dimensional plane. Comment on the mapping - Draw the set Z on a two-dimensional plane.

  Write a matlab program to generate a data file

1.) Write a Matlab program to generate a data file containing the names and corresponding telephone numbers of the customers. 2.) Using the data file created, write a program in Matlab to create a menu-driven facility to preform the following tasks

  Fourier transform and biosignal analysis

Fourier Transform and Biosignal Analysis - series data into its frequency components for the purpose of signal analysis and processing.

  Function that takes as input parameters

Define a function that takes as input parameters a function handle f, start and end values a and b, and a number of steps n. The function should compute and return the x and y values of the maximum of the function over the range a to b.

  Generate a sample of the exponential distribution

MS455/MS555 Project - Simulation in Finance. Use the inverse transforms method to generate a sample of the exponential distribution with parameter θ, which is given by its density

  Create a script that creates a random vector

Create a function called "hollowSphere" that calculates the volume using the formula shown in Problem I. Then write a script that prompts the user for the value of the inner radius and outer radius, your script will then call the function that you..

  Identify potential scorecards for use

Applied Portfolio & Risk Management (FIN 30240) Complete an analysis of the data set and conduct any data manipulations that may be required

  Give the gradient operator in paraboloidal coordinates

Given that the le data.txt contains only real numbers seperated by white space, write down a sequence of maple commands that will read the data into a maple list and then plot a histogram of the elements in the list.

  Matlab program to compute how much money will accumulate

Write a MATLAB program to compute how much money will accumulate in 5 years in the account and in any CDs you buy. Run the program for two different savings interest rates: 4 percent and 5 percent.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd