Welcome to R.pdf

Welcome to R
Write a script to solve these Problems.
Submit your Question and Answers to [email protected]
1. Create a vector of the values of ex cos(x) at x = 3, 3.1, 3.2, . . . , 6.
2. Create the following vectors:
(a) (0.13 0.2 1, 0.1 60.2 4,…, 0.1 360.2 34)
(b) ( 2,
22 23
2
,
3
,… ,
225
25
)
1. Calculate the following:
3
2
(a) βˆ‘100
𝑖=10(𝑖 + 4𝑖 )
2𝑖
3𝑖
𝑖
𝑖
(b) βˆ‘25
𝑖=1 ( + 2 )
2. By using the function cumprod or otherwise, calculate
1+
2
24
246
2 4 38
) + β‹―+ ( … )
+( )+(
3
35
357
3 5 39
3. Solve the following system of linear equations in five unknowns
x1 + 2x2 + 3x3 + 4x4 + 5x5 = 7
2x1 + x2 + 2x3 + 3x4 + 4x5 = βˆ’1
3x1 + 2x2 + x3 + 2x4 + 3x5 = βˆ’3
4x1 + 3x2 + 2x3 + x4 + 2x5 = 5
5x1 + 4x2 + 3x3 + 2x4 + x5 = 17
By considering an appropriate matrix equation Ax = y.
Make use of the special form of the matrix A. The method used for the solution should
easily generalise to a larger set of equations where the matrix A has the same structure;
hence the solution should not involve typing in every number of A.
4. Write a function tmpFn(xVec) such that if xVec is the vector x = (x1, . . . , xn) then
tmpFn(xVec) returns the vector of moving averages:
π‘₯1 + π‘₯2 + π‘₯3 π‘₯2 + π‘₯3 + π‘₯4
(π‘₯π‘›βˆ’2 + π‘₯π‘›βˆ’1 + π‘₯𝑛 )
,
,...,
3
3
3
Try out your function; for example, try tmpFn( c(1:5,6:1) ).
5. Suppose x0 = 1 and x1 = 2 and
π‘₯𝑗 = π‘₯π‘—βˆ’1 +
2
π‘“π‘œπ‘Ÿ 𝑗 = 1,2, …
π‘₯ (𝑗 βˆ’ 1)
Write a function testLoop which takes the single argument n and returns the first n βˆ’
1 values of the sequence {xj}jβ‰₯0: that means the values of x0, x1, x2, . . . , xnβˆ’2.