Midterm solution for MAE 185

by Nasser Abbasi

UNIX COMMANDS

less work this command displays the content of the file to standard output. Here the file is called 'work'. It allows backward and forward movement. The less command does not have to read the whole file to memory before starting to display its content, which can be useful for large files as it can be faster.

more work this command displays the content of the file to standard output. The display is made one page at a time. the command more does not have the advantages that the command less has mentioned above.

pwd print the name of the current working directory.

wc -l the command 'wc' with the argument '-l' counts and prints the number of new lines in its input.

!p This command reissues the first occurence in the commands history file the command that starts with the letter 'p'. It has the same effect as if one typed the same command again. It saves one from having to retype that command fully again.

LINEAR SYSTEMS

Given MATH

(1) write the system of equations in matrix form (3pt)

Answer:

MATH

(2) Solve the system $Ax=b$ using cramer Rule. Show all steps. (5pt)

Answer:

In cramer rule we write MATH

Where $A_{i}$ is the matrix $A$ with the $i^{th}$ column replaced by the $b$ column.

Start by finding MATH MATH

Now find $A_{1},A_{2},A_{3}$

MATH

Similarly

MATH

And finally

MATH

Hence

MATH

(3) Solve the system $Ax=b$ using Gaussian elimination method using partial pivoting. Show all steps. (5 pts).

Partial pivoting means the interchanging of rows only. Full pivoting is where we interchange both rows and columns. Here we are asked to use partial pivoting, which is the common method we learned.

Start by writing down the augmented matrix $M=A|b$

MATH

The goal is to convert the above matrix to this form

MATH

Then we preform back substitutions to solve for $x,y,z$

Now we start the process.

From the augmented matrix, make the first row the row with the smallest first element. This is called the pivot row and the first element in that row is the pivot element. So switch third row with the first row we obtain

MATH

Now add $2\times$first row to the second row and add 12$\times$first row to the 3rd row we obtain

MATH

Now we are done with the first row, we want the second row to be the pivot row with the element $a_{2,2}$ the pivot element. Again we want the pivot element to be the smallest element. But not zero as the case is now. so we need to switch row 2 with row 3 to obtain

MATH

This completes the forward elimination process. So now rewrite the system of equations, we obtain

MATH

Now do the Back substituion process. From the last row we solve for $z$

MATH

Hence from second row we obtain MATH $\ $

Now, from the first row MATH

So final answer is MATH which agrees with cramer rule method as expected.

Taylor Series

Provide the first 3 terms in Taylor series for the following (3pts)

Taylor expansion is MATH

Apply the above using the first 3 terms only, we obtain for

MATH

MATH

MATH

Let $\delta h=-\delta x$ hence we need to expand MATH , and from above it is

MATH

Now replace $\delta h$ back by $-\delta x$ the above becomes

MATH

Hence

MATH

MATH:

Let MATH be a function called $g\left( x\right) $ and apply Taylor expansion on MATH we obtain from above

MATH

Now replace $g$ back by $f^{\prime}$we obtain

MATH

MATH

Here we expand MATH around the point $a=0$ hence since another way to write Taylor series is

MATH

Where in the above we expand $f\left( x\right) $ around $x=a$

Then we obtain

MATH

The above is expanding using 3 terms in the Taylor series of MATH around zero.

To obtain 3 terms in the final series, we need to take more terms in the taylor expansion to obtain

MATH

Non-Linear system

Determine the lowest positive root of MATH

using Newton-Raphson method (3 iterations, $x_{i}=0.3\,$) (9pts)

First note that MATH

In NR method, the iteration step is

MATH

Hence starting with$\ i=1$ and $x_{1}=0.3$ we obtain

MATH

MATH

MATH

Hence using 3 iterations the smallest root found starting from $x=0.3$ is

$0.170\,28$

Using the secant method with $x_{n-1}=0.5$ and $x_{n}=0.4$ (9pts)

In secant method, the iteration process is

MATH

Hence with $x_{1}=.4$ and $x_{0}=.5$ we start the process with $n=1$

MATH

MATH

MATH

Hence using 3 iterations the smallest root found using secant method is

$0.178\,99$
compare to Netwon's method
$0.170\,28$

Algorithm implementation

Implement Euler method to solve a first order ODE in FORTRAN (7pts)

Given an ODE such as MATH with some initial conditions such as MATH

The Euler method algorithm solves for $x\left( t\right) $ as follows

MATH

where for $n=0$ we use the initial condition. Hence $x_{0}=k$