Publications by Author: Mahdi-Massahi
Linear Algebra Exercises in R
Section 1-2 Let B and A be a 2 by 2 matrix and ‘a’ a numeric constant as following. Note: function runif(n, min, max), generates n numbers of random values using uniform distribution in max and min boundary. A <- matrix(runif(2*2, min=0, max=10), ncol=2) B <- matrix(runif(2*2, min=0, max=10), ncol=2) a <- runif(1) print(A) ## [,1] [,2] #...
660 sym R (762 sym/18 pcs)
Cramer Implementation in R
Cramer’s Rule In linear algebra, Cramer’s rule is an explicit formula for the solution of a system of linear equations with as many equations as unknowns, valid whenever the system has a unique solution. It expresses the solution in terms of the determinants of the (square) coefficient matrix and of matrices obtained from it by replacing one ...
4536 sym R (2136 sym/12 pcs) 1 img
Euler's Totient Function in R
Step 1 First we need to define a function to get all prime numbers smaller than the input value. AllPrimes <- function(x){ primes <- c() for (num in 1:x){ is.prime <- F if (num > 1) { is.prime = T for (i in 2:(num - 1)) { if ((num %% i) == 0) { is.prime <- F break } } ...
436 sym R (1180 sym/22 pcs) 1 img
Series 4 Ans of Numerical computation
Question no. 1 Constructing matrix A: A <- matrix( c(2, 4, -4, 1, 3, 6, 1, -2, -1, 1, 2, 3, 1, 1, -4, 1), byrow=T, nrow=4, ncol=4) A ## [,1] [,2] [,3] [,4] ## [1,] 2 4 -4 1 ## [2,] 3 6 1 -2 ## [3,] -1 1 2 3 ## [4,] 1 1 -4 1 Constructing vector b: b <- matrix(c(0,-7,4,2), nrow=4, ncol=...
1121 sym R (4300 sym/48 pcs) 4 tbl
Numerical Analysis Serie 3 - v1.0
Question no. 1 func <- function(x) { x - 25^1/3 } curve(func, xlim=c(6,10), col='blue', lwd=1.5, lty=2) abline(h=0) abline(v=0) Lets define bisection method as: bisection <- function(f, a, b, n = 1000, tol = 1e-7) { if (f(a)*f(b) > 0) { stop('signs of f(a) and f(b) does not differ') } for (i in 1:n) { c <- (a + b) / 2...
2653 sym R (4215 sym/40 pcs) 13 img
Root finding
Genetic Algorithm In this document we will be descause about GA algo. and function root finding. First of all GA library must be installed from CRAN. suppressWarnings({ if(!require(GA)) install.packages("GA")}) ## Loading required package: GA ## Loading required package: foreach ## Loading required package: iterators ## Package 'GA' version ...
2926 sym R (3825 sym/33 pcs) 12 img
Some methods for linear regression, GA, GD, and R-base lm
Functin definition First of all, we define a linear function. Because the magnitude and intercept (a, and b) will be constant during this project, I will not pass them to the function as arguments. a <- 5 b <- 0.2 linear_function <- function(x){ return(a*x + b) } Sample creation The function curve() gives us samples over the function we pass ...
4208 sym R (4770 sym/14 pcs) 6 img