Answered step by step
Verified Expert Solution
Question
1 Approved Answer
( 6 pts . ) Write the system of equations as a matrix - vector system . Generate the solution to the system of equations
pts Write the system of equations
as a matrixvector system
Generate the solution to the system of equations by computing the
factorization of the matrix
by hand and using this factorization to solve for
Do not using pivoting to find your factorization. Validate the solution you obtain without solving the system again. That is do not use MATLAB to solve the system, do not refactor, do not resolve the system using the factors, and do not find an inverse.
pts For this problem, you will need to write two MATLAB functions. Write one function that takes as input a matrix
and a vector
and outputs the solution
to the linear system
using the MATLAB operator. This function is referred to as matlabSolve in the script given below.
For the second function, the input should allow for the
and
factors of
as well as a righthand side vector
The output should be the vector
that is the solution to
This function is referred to as luSolve in the script below. You can use the MATLAB operator to solve each of the triangular systems associated with the
and
factors.
Write a script to solve a matrix system defined using a matrix of size
and a matrix of size
with random entries. Populate the righthand side vector
with random entries as well. The MATLAB function rand can be used to generate both the matrix and the vector. Note the size of
will need to correspond to the size of
Obtain an overall timing to assess the difference between the functions. You can obtain timings using the MATLAB tic and toc commands. When using the MATLAB command to solve the matrix system, the
factors are generated each time, at a cost of
operations. The upper and lower triangular solves are performed next, each with an operation count of
Your script file might look like the following.
enter the size of the matrix
n ;
define the matrix A with random entries
A randnn;
generate the righthand side vector with random entries
b randn;
determine how many times to run the experiment
m ;
start timing for the first function call
tstartBackslash tic;
solve the system n times and record the results
for i :m
solve the system
xSolns matlabSolveAb;
generate the righthand side vector b by multiplying
the old righthand side by different random numbers
b randlengthb b;
end
end the timings
telapsedBackslash toctstartBackslash
now repeat with the second function
You now have to compute the LU factors of A
before making the function call
start the clock
tstartLU tic;
find the LU factors of A
LU luA
solve the system n times and record the results
for i :m
solve the system
xSolns luSolveLUb;
generate the righthand side vector b by multiplying
the old righthand side by different random numbers
b randlengthb b;
end
end the timings
telapsedLU toctstartLU
Report your timings and your final results. Discuss why one method takes less time than the other. What happens to the timings as you increase the number of times you execute the loops?
pts Problem in the linear algebra notes Download linear algebra notes in the text Numerical Computing with MATLAB by Cleve Moler contains a system of linear equations associated with a truss system. The matrix for this system of equations can be generated using the script generateTrussMatrix Download generateTrussMatrix.
The value of
describes the angle between components of the truss system. In this exercise, you will change the value of
and see how it changes the condition number of the matrix. You will also determine how the change in condition number affects the computed solution.
In order to understand the effect on the solution, generate the righthand side vector
so you know what the true solution is Generate a vector of all ones that has the same number of rows as the matrix
This can be done using
xtrue oneslengthA;
Generate the vector
by multiplying
by this vector of all ones. Then, when you solve
the solution should be a vector of all ones. This procedure has been added to the file which generates the truss matrix.
Start with
compute the solution, and compare the computed solution to the known true solution ie the vector of all ones Find the condition number of
and note the number of correct significant digits in the computed solution. Reduce the value of
by a factor of
until you have
around
Make a table with the value of
in one column, the condition number of
in a second column, and the number of correct digits in the computed solution in the third column. Do these data support the connection between loss of significant digits and the condition number discussed in
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started