Suggetsed solutions could be found by these links: page_rank.m, run_rank.m, boole.m (using "for" loop), better_boole.m (using vector arithmetic), run_boole.m.
The assignment is due Monday, July 24, 11:59pm.
Due to some reasons we can not use public folder anymore. Please email me (o.dykhovychnyi@wsu.edu) your files instead of uploading them to your public folder.
Assignment is worth 110 points.
Part 1 (45 points).
In this part you are required to create a MATLAB script named "run_rank.m" and a MATLAB function file named "page_rank.m".
The "run_rank.m" script should do the following:
 Load a square matrix from this file to the matrix variable M. The matrix descibes primitive network of 8 web pages using CSV format. Since the function I showed you in class requires some additional actions to get a matrix variable, you may use dlmread function. This function returns exatly what you need. More details on usage could be found here.
 Compute PageRank vector for the network descibed by M by calling page_rank(matr, alpha, e) function (which you are supposed to define
in this file in a separate file as described below) with damping factor 0.85 and precision 10^{6}. The output should be stored into the vector variable named v and immediately printed to the console.
 Plot computed PageRank vector v using bar function. More details on usage could be found here. The axes should be labeled as "Pages" (xaxis) and "Rank" (yaxis).
The "page_rank.m" file should define the page_rank(matr, alpha, e) function as follows:
 The function has 3 input parameters:
 matr  matrix descibing network of some web pages.
 alpha  damping factor.
 e  precision.

The function returns a columnvector  PageRank vector.
 The function shoud implement PageRank algortithm used by Google search engine to rank web pages resulting from a particual search query. The input of the algorithm is an adjacency matrix (input parameter matr) of a directed graph describing some particual network of web pages (see also this link). The algorithm transforms given matrix to a so called Google Matrix using given damping factor (input parameter alpha). Then the algorithm finds the eigenvector corrseponding to the dominant eigenvalue (the ones with the largest magnutude) of the Google Matrix using power iteration method (recall the document you typest in the previous assinment). The computed eigenvector called PageRank vector and it represents the probability distribution of the likelihood that a person randomly clicking on links will arrive at any particular page. This vector is the output of the algorithm. There are dozens of online materials explaining this algorithm, e.g. this one or the original article.
 The Google Matrix ($G$) should be computed from the adjacency matrix ($A$) as follows:
$$\text{First, compute matrix \hspace{0.17em}}B=\left({b}_{i,j}\right)\text{\hspace{0.17em} from matrix \hspace{0.17em}}A=\left({a}_{i,j}\right)\text{\hspace{0.17em} by dividing every element of \hspace{0.17em}}A\text{\hspace{0.17em} by the sum of all elements of the column to which given elemnt belongs, i.e.\hspace{0.17em}}{b}_{i,j}=\frac{{a}_{i,j}}{\sum _{k=1}^{\mathrm{N}}{a}_{k,j}}$$
$$\text{Then \hspace{0.17em}}G=\alpha B+(1\alpha )\frac{1}{N}C\text{, where \hspace{0.17em}}N\text{\hspace{0.17em} is the size of the square matrices \hspace{0.17em}}A,B\text{\hspace{0.17em} and \hspace{0.17em}}C\text{; C is simply a matrix of all ones, i.e. \hspace{0.17em}}C=\left[\begin{array}{cccc}1& 1& \cdots & 1\\ \vdots & \vdots & \ddots & \vdots \\ 1& 1& \cdots & 1\end{array}\right]$$
Note that you will probably need "for" loop (to iterate over all columns of the matrix, but not rows!) together with sum function to compute $B$. More on sum function usage could be found here.
The $G$ matrix could be computed just with one line as soon as you got the $B$ matrix.

The power iteration method is extremely simple:
 You start with the vector ${x}_{0}$ representing uniform distribution, i.e. all cordinates are $\frac{1}{\mathrm{N}}$
 Your first iteration should compute vector ${x}_{1}$ by multiplying ${x}_{0}$ by your Google Matrix $G$, i.e. ${x}_{1}=G{x}_{0}$
 Every next iteration ($k$) will also multiply vector obtained from preceeding iteration ($k1$) by your Google Matrix $G$, i.e. ${x}_{k}=G{x}_{k1}$ .
 The algorithm should stop when ${\parallel {x}_{k}{x}_{k1}\parallel}_{2}=\sqrt{{({x}_{k}^{1}{x}_{k1}^{1})}^{2}+\cdots +{({x}_{k}^{n}{x}_{k1}^{n})}^{2}}\le e$, where $e$ denotes precision specified by the input parameter e.
 Then your PageRank vector is simply ${x}_{k}$.
Note that you probably will need to use "while" loop to implement this algorithm, and the variables for ${x}_{\mathrm{k}}$ and ${x}_{\mathrm{k}1}$ (which are columnvectors) should be defined before starting the loop (you can define ${x}_{\mathrm{k}1}$ with all zeroes and ${x}_{\mathrm{k}}$ as descibed in (a)). Also note that the expression used in (d) is called 2norm or Euclidean norm of a vector (in your case vector which norm is computed is obtained by substracting vectos ${x}_{\mathrm{k}}$ and ${x}_{\mathrm{k}1}$) and norm function may be useful here. More details on usage could be found here.
 Note that your function should be able to process matrices of any size, i.e. you should not hardcode any particual size of matrix N inside your function. Instead it should be derived (and probably stored into some variable) inside your function by applying proper builtin function to your matrix matr.
 Your function should check whether input matrix matr is really a square matrix. If not, an error with a proper message should be raised using error function.
 Your function should not print any output messages to the console.
The diagram produced by your script should look like this.
Part 2 (45 points)
In this part you are required to create a MATLAB function named boole. The function should be stored in a separate file with a proper name.
This function should implement numerical integration algorithm using one of the Newtonâ€“Cotes formulas called Boole's rule:
 The function has 3 input parameters:
 fun  function to be integrated (function_handle data type).
 a  lower limit of integration.
 b  upper limit of integration.
 n  number of partitions.

The function returns a floating point number  value of the defintie integral.
 Here is how Boole's rule work.
Consider the integral
\[\int_a^b f(x)\,dx\]
where \(f\) (fun input parameter) is twice continuously differentiable.
Let \(a=x_0\lt x_1\lt\dots\lt x_n=b\) be an
equallyspaced partition of \([a,b]\) (a and b input parameters),
where we assume that \(n\) (n input parameter) is evenly divided by 4.
When \(h=(ba)/n\) is the uniform width of the subintervals,
then accroing to Boole's rule your integral can be estimated as
\[\int_a^b f(x)\,dx \sim
\frac{2h}{45}\sum_{i=1}^{n/4} \left(
7f(x_{4i4})+32f(x_{4i3})+12f(x_{4i2})+32f(x_{4i1})+7f(x_{4i})
\right).
\]
 (You can skip/ignore this step!)Your function should plot two things: original function on the given interval (using grid with n*10 points or more) as a blue solid line without any point markers; and values of your function at endpoints of all subintervals (i.e. \(f(x_0), f(x_1), \dots, f(x_n)\)) as a dashed red line using "x" points marker. For this purpose you should probably store both endpoints of your subintervals and values of your function at this points while doing computations, and then use these two sets to create the plot. The axes should be labeled properly, e.g. "x" and "f(x)".
 Your function should check whether values provided for a and b satifsfy a < b. If not, an error with a proper message should be raised using error function.
 Your function should check whether provided number of subintervals n is divisible by 4. If not, an error with a proper message should be raised using error function.
 Your function should not print any output messages to the console.
Part 3 (20 points)
In this part you are required to create a MATLAB script named "run_boole.m".
The script shoud test the boole function created in Part 2 and do the following:
 Define 3 anonymous functions (inline functions):

f1 = \( \sin(x)  + \cos(x) + x \) on [π , π]

f2 = \( \frac{1}{x} \) on [0.1, 5.1]

f3 = \( x^3  2 x^2  5x + 1 \) on [3, 4]

For each of the above functions do the following:
 Compute the value of the integral on the given interval using builtin inegral function. You will use this value as a reference value to compute error.
 Compute the value of the integral on the given intervals using your boole function for five different partitions: n=4^1=4, n=4^2=16, n=4^3=64, n=4^4=256 and n=4^5=1024. All the computed values should be saved for the next step.(if you skipped step 4 of part 2, you can also skip the following highlighted stuff!)After computing integral for each of the given partitions, pause the script execution for 1 seconds. For this purpose you may use pause(1) function. More details on usage could be found here.
 Plot the following:
 xaxis: powers of 4 that used to compute number of subintervals for every step in (b), i.e. n=1, n=2, n=3, n=4 and n=5;
 yaxis: computation error, i.e. absolute value of the difference between the value computed with inegral function (step (a)) and the value computed with your boole function (step (b)) using corresponding partitioning.
The axes should be properly labeled, e.g. "Number of subintervals" and "Error". The title of your plot should be the name of the function and corresponding interval, e.g. "f3 on [3, 4]"
 The script execution should be paused and wait for user input. For this purpose you may use waitforbuttonpress function. ore details on usage could be found here
Publishing your results.
As soon as you are done with all of the above, upload all the "*.m" files (4 files) to ~/public/homeworks/hw04 directory on adams.math.wsu.edu. Obviously, if directory doesn't exist yet, it should be created.
As soon as you are done with all of the above, send all your "*.m" files (4 files) to o.dykhovychnyi@wsu.edu.