====== Differences ====== This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
gibson:teaching:fall-2013:math445:exam1solns [2013/10/28 13:06] gibson created |
gibson:teaching:fall-2013:math445:exam1solns [2013/10/29 06:14] (current) gibson |
||
---|---|---|---|
Line 62: | Line 62: | ||
</latex> | </latex> | ||
+ | A = [ 3 1 2; -1 0 9; -4 5 0]; | ||
+ | b = [6; 8; 1]; | ||
+ | x = A\b | ||
+ | | ||
+ | **9.** Write a Matlab function that computes the mean (i.e. average) of | ||
+ | the components of a vector $x$ according to the formula | ||
+ | |||
+ | <latex> | ||
+ | \text{mean}(x) = (1/N) \sum_{i=1}^{N} x_i | ||
+ | </latex> | ||
+ | |||
+ | where $N$ is the length of the vector. Your function should evaluate this | ||
+ | sum directly instead of using the Matlab %%sum%% or %%mean%% functions. | ||
+ | |||
+ | function m = mean(x) | ||
+ | % compute mean of vector x | ||
+ | | ||
+ | m = 0; | ||
+ | N = length(x); | ||
+ | | ||
+ | for i=1:N | ||
+ | m = m + x(i); | ||
+ | end | ||
+ | | ||
+ | m = m/N; | ||
+ | end | ||
+ | | ||
+ | **10.** Write a Matlab function that takes an $M \times M$ transition | ||
+ | matrix $T$ for a network of $M$ web pages and returns the page rank vector $p$ | ||
+ | of the steady-state distribution of visitors to each page. The page rank is | ||
+ | given by $p = T^n e$, where $e$ is an arbitrary $M$-vector whose components | ||
+ | sum to 1, and $n$ is large number. You can set $n$ to 100. | ||
+ | | ||
+ | function p = pagerank(T); | ||
+ | % compute that page rank vector for transition matrix T | ||
+ | | ||
+ | [M,M] = size(T); | ||
+ | | ||
+ | e = zeros(M,1); | ||
+ | e(1) = 1; | ||
+ | | ||
+ | n=100; | ||
+ | | ||
+ | p = T^n * e; | ||
+ | | ||
+ | end | ||
+ | | ||
| |