Upload your solution as a PDF and the relevant . ml x and/or . mles to the Canvas page.
Purpose: reinforce your understanding in numerical integration of a given continuous function and practice programming skills in MATLAB.
This is a BONUS Homework (HW). Your grade will replace your smallest HW grade or missing HW.
B ackground: The approximation
Z x+ x
f (x) dx f (x) x (1)
x
can be obtained in a similar way to the nite dierence approximation we did before for numerical derivatives[1]. Recall that the step size x must be small such that x <<< 1.
Using the approximation given in eq. (1), we can calculate the denite integral R
of the given function f (x) between the bounds a and b by
rst dividing the interval [a;b] into uniform discrete intervals with step size where n is the number of discrete intervals
then calculating the total shaded area under the curve f (x) shown below in the gure.
The total shaded area is a numerical approximation to the integral
. Note that the step size is
because n = 7. The step size determines the level of accuracy. Decreasing the step size x or increasing the number of intervals (for example, n > 7) will decrease the error in the approximation of the integral[2]. This approximation of the integral is called the Reimann Sum.
1
Homework no. 8
(Left Reimann Sum - LRS) Considering the values of f (x) at the left of the discrete intervals,
we can approximate the integral as follows:
Z b Z x1 Z x2 Z x3 Z b
f (x)dx = f (x)dx + f (x)dx + f (x)dx + + f (x)dx
a a x1 x2 x6
= f (a) x + f (x1) x + f (2) x + + f (x6) x
For ease of implementation in MATLAB, the general form (for any n) of LRS is given below
(2)
(Right Reimann Sum - RRS) Considering the values of f (x) at the right of the discrete intervals,
we can approximate the integral as follows:
(3)
Q uestions: For the given integral below
Calculate the LRS with n = 5 by implementing eq. (2) in a user function in MATLAB. This function takes the function handle for f (x) and the number n, and returns the LRS approximation of the integral.
Calculate the RRS with n = 5 by implementing eq. (3) in a user function in MATLAB. This function takes the function handle for f (x) and the number n, and returns the RRS approximation of the integral.
Calculate the absolute and relative percent errors for the results obtained in parts a and b.
The true solution is.
Repeat parts a-c for n = 50 and n = 500.
Summarize your ndings in a table. C omment on your results.
2
Homework no. 7
Homework 7: Solving system of linear equations
(due on Friday, Dec 3, 2021)
Upload your solution as a PDF and the relevant . ml x and/or . mles to the Canvas page.
Purpose: introduce you to computer methods for solving systems of simultaneous linear equations. You will perform hand calculations that solves the equations using Gauss Elimination (direct solver) and Gauss-Seidel (iterative solver) approaches and then and write a computer program that does the same.
Problem 1: Given the system of equations Ax = b, as dened below:
2 2 2 1 32x13 2 10 3
4 3 2 554x25 = 4 165
1 2 3 x3 8
Use MATLAB’s backslash operator ‘\’ to solve
Determine the solution by hand using Gauss Elimination
Use Gauss-Seidel method to solve (by implementing a function that performs Gauss-Seidel iterations for a given matrix A and vector b.)
Problem 2: Given the system of equations Ax = b, as dened below:
2 8 2 332x13 2513
4 2 5 154x25 = 4235
3 1 6 x3 20
Use MATLAB’s backslash operator ‘\’ to solve
Carry out three iterations of the Gauss-Seidel method by hand, assuming an initial values of x equal to zero. After the third iteration, compute the error for each estimate with relative to the true values (you can use backslash operator to obtain the true solution.)
Use Gauss-Seidel method to solve (by implementing a function that performs Gauss-Seidel iterations for a given matrix A and vector b.)
1
Homework no. 7
Problem 3: Solve the axial forces F i for the following truss with pin-joints and 13 members. The resulting system of 13 equations is:
F2 + 0:707F1 = 0 F3 0:707F1 2000 = 0
0:707F1 + F4 + 6229 = 0 F2 + 0:659F5 + F6 = 0
F4 0:753F5 600 = 0
F3 0:659F5 + F7 = 0
F8 + 0:753F5 = 0
F6 + 0:659F9 + F10 = 0
F8 0:753F9 800 = 0
F7 0:659F9 + F11 = 0
F12 + 0:753F9 2429 = 0
F10 + 0:707F13 = 0
F12 0:7071F13 600 = 0
How many unknowns and how many equations does the system of equations have?
Solve this system of equations using the backslash operator
Solve this system of equations using your Gauss-Seidel function (implemented in Problem 1) using initial values of F equal to zero.
Explain what is happening when you try to solve this problem using Gauss-Seidel.
2
[1] Try to derive this relation from Taylor series - post any questions on Piazza!