Type: | Package |
Title: | Tropical Algebraic Functions |
Version: | 0.1.1 |
Maintainer: | Muhammad Kashif Hanif <mkashifhanif@gcuf.edu.pk> |
Description: | It includes functions like tropical addition, tropical multiplication for vectors and matrices. In tropical algebra, the tropical sum of two numbers is their minimum and the tropical product of two numbers is their ordinary sum. For more information see also I. Simon (1988) Recognizable sets with multiplicities in the tropical semi ring: Volume 324 Lecture Notes I Computer Science, pages 107-120 <doi:10.1007/BFb0017135>. |
Depends: | R (≥ 3.3.0) |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 6.0.1 |
NeedsCompilation: | no |
Packaged: | 2018-01-21 10:12:29 UTC; IBNE |
Author: | Muhammad Kashif Hanif [cre, aut], Rehman Ahmad [aut], Karl-Heinz Zimmermann [aut], Zia ul Qayyum [aut] |
Repository: | CRAN |
Date/Publication: | 2018-01-21 17:27:24 UTC |
Copy Matrices
Description
This function copies the first matrix in second one. Thhis fucntion will work only if both matrices are of same size.
Usage
copyMatrix(X,Y)
Arguments
X |
A matrix to be copied. |
Y |
Target Matrix. |
Details
If the size of source and target matrices are not same it generates an error.
Value
Returns Y
Matrix.
Examples
X<-matrix(c('a','b','c','d'),nrow=2, ncol=2)
Y<-matrix(c(NA,NA,NA,NA),nrow=2, ncol=2)
copyMatrix(X,Y)
Copy Vectors
Description
This function copies the first vector in second one. This fucntion will work only if both vectors are of same length.
Usage
copyVector(x,y)
Arguments
x |
Vector to be copied. |
y |
Target vector. |
Details
If the length of source and target vectors are not same it generates an error.
Value
Returns y
.
Examples
x<-c(1,2,3,4)
y<-c(NA,NA,NA,NA)
copyVector(x,y)
Swap Matrices
Description
This function interchanges the values of both matrices.This function works only if both matrices are of same size.
Usage
swapMatrix(X,Y)
Arguments
X |
A matrix. |
Y |
A matrix. |
Details
If the size of both matrices are not same, it generates an error. This function swaps the matrices in memory(like pass by reference), it does not return the matrices, but interchanges their values.
Value
Swapped Matrix X
and Y
.
Examples
x<-matrix(c(2,3,5,7),ncol=2,nrow=2)
y<-matrix(c(6,3,1,9),ncol=2, nrow=2)
swapMatrix(x,y)
Swap Vectors
Description
This function swaps the values of both vectors. This function works only if both vectors have equal length.
Usage
swapVector(x,y)
Arguments
x |
A vector. |
y |
A vector. |
Details
If the lengths of both vectors are not same, it generates an error. This function swaps the vectors in memory(like pass by reference), it does not return the vectors, but interchanges their values.
Value
Swapped vectors x
and y
.
Examples
x<-c(6,7,8)
y<-c(3,2,1)
swapVector(x,y)
Tropical Sum Function
Description
Calculates tropical sum of numeric values. This function workks only if arguments are numeric values. The tropical sum of two numbers is the minimum number. If arguments are not numeric values then it generates an error. If a vector is passed as argument to the funcion it will return the tropical sum of all the elements in the vector.
Usage
tadd(...)
Arguments
... |
Any number of numeric values or a single vector. |
Details
The tropical sum of two numbers is the minimum number. This function returns the minimum of arguments. If arguments are not numeric values then it generates an error.
Value
Returns tropical sum of arguments.
Examples
x<-5
y<-6
tadd(x,y)
Tropical Sum of Matrices
Description
This funciton sums two matrices(first matrix scaled by alpha
, if user doesnt't pass alpha
first matrix will not be scalled) and return the resultant matrix.This function works only if both matrices are numeric and of same size, and alpha is a numeric value.
Usage
tmatrixAdd(x,y,alpha=0)
Arguments
x |
A numeric Matrix. |
y |
A numeric Matrix. |
alpha |
A numeric value. |
Details
If either the size of both matrices is not same or if any one or both matrices are not numeric matrix or alpha is not a numeric value then it will generates an error.
Value
Returns the tropical sum of x
(scalled by alpha
) and y
.
Examples
x<-matrix(c(2,3,5,7),ncol=2,nrow=2)
y<-matrix(c(6,3,1,9),ncol=2, nrow=2)
alpha<-5
tmatrixAdd(x,y,alpha)
Tropical Product of Matrices
Description
This function returns the product of two matrices. This function works only if columns of first matrix eqaual to rows of seconnd matrixs.
Usage
tmatrixMultiply(X,Y)
Arguments
X |
A numeric Matrix. |
Y |
A numeric Matrix. |
Details
If number of columns of first matrix is not equal to the number of rows of second matrix or any one matrix is not a numeric matrix then this functions generates an error. If mxn is first matrix and axb is a second matrix then nxa will be the resultant matrix.
Value
Returns the tropical product of X
and Y
Examples
X<-matrix(c(2,3,5,7),ncol=2,nrow=2)
Y<-matrix(c(6,3,1,9),ncol=2, nrow=2)
tmatrixMultiply(X,Y)
Tropical Product Function
Description
The tropical product of two numbers is the odinary sum of numbers. This function returns the tropical product of arguments. If arguments are not numeric values then it generates an error. If a vector is passed as argument to the funcion it will return the tropical product of all the elements in the vector.
Usage
tmultiply(...)
Arguments
... |
Any number of numeric values or a single vector. |
Details
The tropical product of two numbers is the oridnary sum of numers. This function returns the tropical product of arguments. If arguments are not numeric values then it generates an error.
Value
Returns tropical product of arguments.
Examples
x<-6
y<-5
tmultiply(x,y)
Transpose of a Matrix
Description
This fucntion interchage the rows into columns or columns into rows.
Usage
transpose(X)
Arguments
X |
A Matrix. |
Details
If the given argument is not a matrix this function generates an error, otherwise, it tronsposed the matrix and returns in the same variable that was passed in argument like pass by reference. It changes values in memory.
Value
Returns transposed matrix X
.
Examples
X<-matrix(c(2,5,3,7),ncol=2,nrow=2)
transpose(X)
Tropical Scaling of Matrix Or vector
Description
This function returns the scaled matrix or vector Y
by a value x
.This function works only if Y
is matrix or vector and x
is a numeric value.
Usage
tscale(x,y)
Arguments
x |
A numeric value. |
y |
A numeric matrix or a numeric vector. |
Details
If the given argument x
is not a numeric value or argument Y
is not a numeric matrix or a numeric vector then this function generates an error.
Value
Returns the scaled Y
.
Examples
x<-5
y<-matrix(c(2,3,5,7),ncol=2,nrow=2)
tscale(x,y)
y<-c(1,2,3)
tscale(x,y)
Tropical Sum of Vectors
Description
This function add two or more vectors and returns the resultant vector. This function works only if vectors are of same length.
Usage
tvectorAdd(...)
Arguments
... |
Any number of numeric vectors. |
Details
If the arguments are not numeric vectors and are not of same length, this function generates an error. If a single vector is passed to the function it will return the tropical sum of all the elements in the vector.
Value
Returns tropical sum of argumented vectors.
Examples
x<-c(5,6,7)
y<-c(1,2,3)
tvectorAdd(x,y)
Tropical Product of Vectors
Description
This function multiplies two or more vectors and returns the resultant vector. This function works only if vectors are of same length.
Usage
tvectorMultiply(...)
Arguments
... |
Any number of numeric vectors. |
Details
If the arguments are not numeric vectors and are not of same length, this function generates an error. If a single vector is passed to the function it will return the tropical product of all the elements in the vector.
Value
Returns the product of argumented vectors.
Examples
x<-c(5,6,7)
y<-c(1,2,3)
tvectorMultiply(x,y)
Tropical Vector Matrix Product
Description
This function returns a vector in result of vector matrix tropical product.This function works only if length of vector equal to number of columns of matrix.
Usage
tvectotMatrixProduct(Y,x)
Arguments
Y |
A numeric matrix. |
x |
A numeric vector. |
Details
If the given argument x
is not a numeric vector or argument Y
is not a numeric matrix and the length of vector is not equal to the number of columns of matrix then the function generates an error.
Value
Returns the tropical product of vectror x
and matrix Y
.
Examples
x<-c(1,2,3)
Y<-matrix(c(1,2,3,4,5,6,1,2,3), nrow = 3, ncol = 3)
tvectotMatrixProduct(Y,x)