Numerical Methods Test 1
Numerical Methods Test 1
Numerical Methods Test 1
2. The bracket [0 1] means xl = 0 and xu = 1, make sure xr = (xl + xu)/2 don’t change any xl or
xu except that first row
3. The question asks for the iteration question so don’t forget to write that down.
5. Drag from the bottom right of the f(xl) box and drag to the right, then drag them down.
6. The question only asks for the first four calculations, so that’s all you have to write down.
Pay attention to the ^-01’s
1. Open up the Newton excel file, honestly probably best if you download a new one each
time
3. Input the function given into f(x_i) using the x_i as the x.
6. The question asks for the first four calculation steps, so you only have to write down the
first four
7. The second question also asks for the question for xi+1 so make sure to write that down.
f (xi )
The general equation for xi+1 is as follows, xi+1 = xi − therefore, the xi+1 equation for this
f '(xi )
2 * xi − (tan(xi ) − 1)2
example is as follows, xi+1 = xi −
−2 *sec 2 (xi ) tan(xi ) + 2 + 2sec 2 (xi )
1. Write down the general formula on paper for a matrix in a linear equation system.
⎡⎣ A⎤⎦ ⎡⎣ X ⎤⎦ = ⎡⎣ b ⎤⎦
⎡ 8 2 3 ⎤ X1 51
⎢ ⎥
⎢ 2 5 1 ⎥ * X 2 = 23
⎢ −3 1 6 ⎥ X3 20
⎣ ⎦
2. If you want to check the answer later on you can input this command initially.
3. Complete LU factorization in MATLAB with the following command.
5. Input values for d using the lower matrix and x using the upper matrix.
6. Create the inverse matrix by making a matrix of x1, x2, and x3.
7. You can check your work by subtracting the MATLAB function of inv and the one you
created.
2. Write out the iterative equations. The general form for the Gauss-Seidel Method is as
follows:
b - a x j-1 - a13 x3j-1
x1j = 1 12 2
a11
b2 - a21 x1j - a23 x3j-1
x2j =
a22
b3 - a31 x1j - a32 x2j
x3j =
a33
The iterative equations for this problem is as follows:
51− 2 * X 2i − 3* X 3i
X =
i+1
1
8
23− 2 * X 1i+1 − X 3i
X 2i+1 =
5
20 + 3* X ii+1 − X 2i+1
X3 =
i+1
6
3. Download the excel file, “ Gauss-Seidel_Jacobi Method”
4. The first row for i, x1, x2, and x3 should all be 0. Input the iterative equations into x1, x2,
and x3.
5. Drag down the cells until x1, x2, and x3 converge to the correct answer from MATLAB’s
output. This happens in less than 10 steps.
6. On paper only write down the first two steps as the question asks.
2x2 + e−4 x1
x1 =
5
2x + e−3x2
x2 = 1
5
2. Assume that x1,o and x2,o are equal to zero, then plug those into the equations and solve. x1
and x2 can be solved using MATLAB must be written out by hand
⎛ 1 ⎞ −3 0
2⎜ ⎟ + e ( )
2 (0) + e
−4( 0 )
1 ⎝ 5⎠
x1,1 = = = 0.2 x2,1 = = 0.28
5 5 5
3. Repeat the same step except with the new values for x1 and x2
2 ( 0.28) + e−4*0.2 2 ( 0.201866 ) + e−3*0.28
x1,2 = = 0.201866 x2,2 = = 0.167088
5 5
4. Only the first two steps have to be written down, so the rest can be solved in excel by
inputting the starting values, x1, and x2.
⎡ ∂f ∂ f1 ⎤
⎢ 1
⎥
⎢ ∂x1 ∂x2 ⎥ ⎡ 5 + 4e−4 x1 −2 ⎤
J=⎢ ⎥=⎢ ⎥
⎢ ∂ f 2 ∂ f 2 ⎥ ⎢⎣ −2 5 + 3e−3x2 ⎥⎦
⎢ ∂x1 ∂x2 ⎥
⎣ ⎦
2. Input into MATLAB the following function as a function file
3. Utilize the Newton-Raphson m-file to find the values for x.
1. input cells for x1, x2, f1, f2, and the sum.
2. Input equation 1 and 2 from problem into f1 and f2 cells, then the sum of their square
roots into the cell “sum sq”
3. Use the excel solver by setting the objective to the sum cell, changing the variable cells, x1
and x2 by dragging over both cells, and setting the objective to the value of 0 since both
equations are equal to 0 in the problem.
4. When you hit solve, the x1 and x2 value will converge to the correct answer.
Using Fsolve
2. Enter the following into the command window utilizing the MATLAB built in function
fsolve, using the parameters [0 0] since f1 = 0 and f2 = 0.
y = −x 2 + x + 0.75, y = x 2 − 5xy