Title: | Tropical Algebraic Functions |
---|---|
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>. |
Authors: | Muhammad Kashif Hanif [cre, aut], Rehman Ahmad [aut], Karl-Heinz Zimmermann [aut], Zia ul Qayyum [aut] |
Maintainer: | Muhammad Kashif Hanif <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.1 |
Built: | 2024-10-31 22:10:36 UTC |
Source: | CRAN |
This function copies the first matrix in second one. Thhis fucntion will work only if both matrices are of same size.
copyMatrix(X,Y)
copyMatrix(X,Y)
X |
A matrix to be copied. |
Y |
Target Matrix. |
If the size of source and target matrices are not same it generates an error.
Returns Y
Matrix.
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)
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)
This function copies the first vector in second one. This fucntion will work only if both vectors are of same length.
copyVector(x,y)
copyVector(x,y)
x |
Vector to be copied. |
y |
Target vector. |
If the length of source and target vectors are not same it generates an error.
Returns y
.
x<-c(1,2,3,4) y<-c(NA,NA,NA,NA) copyVector(x,y)
x<-c(1,2,3,4) y<-c(NA,NA,NA,NA) copyVector(x,y)
This function interchanges the values of both matrices.This function works only if both matrices are of same size.
swapMatrix(X,Y)
swapMatrix(X,Y)
X |
A matrix. |
Y |
A matrix. |
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.
Swapped Matrix X
and Y
.
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)
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)
This function swaps the values of both vectors. This function works only if both vectors have equal length.
swapVector(x,y)
swapVector(x,y)
x |
A vector. |
y |
A vector. |
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.
Swapped vectors x
and y
.
x<-c(6,7,8) y<-c(3,2,1) swapVector(x,y)
x<-c(6,7,8) y<-c(3,2,1) swapVector(x,y)
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.
tadd(...)
tadd(...)
... |
Any number of numeric values or a single vector. |
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.
Returns tropical sum of arguments.
x<-5 y<-6 tadd(x,y)
x<-5 y<-6 tadd(x,y)
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.
tmatrixAdd(x,y,alpha=0)
tmatrixAdd(x,y,alpha=0)
x |
A numeric Matrix. |
y |
A numeric Matrix. |
alpha |
A numeric value. |
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.
Returns the tropical sum of x
(scalled by alpha
) and y
.
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)
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)
This function returns the product of two matrices. This function works only if columns of first matrix eqaual to rows of seconnd matrixs.
tmatrixMultiply(X,Y)
tmatrixMultiply(X,Y)
X |
A numeric Matrix. |
Y |
A numeric Matrix. |
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.
Returns the tropical product of X
and Y
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)
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)
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.
tmultiply(...)
tmultiply(...)
... |
Any number of numeric values or a single vector. |
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.
Returns tropical product of arguments.
x<-6 y<-5 tmultiply(x,y)
x<-6 y<-5 tmultiply(x,y)
This fucntion interchage the rows into columns or columns into rows.
transpose(X)
transpose(X)
X |
A Matrix. |
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.
Returns transposed matrix X
.
X<-matrix(c(2,5,3,7),ncol=2,nrow=2) transpose(X)
X<-matrix(c(2,5,3,7),ncol=2,nrow=2) transpose(X)
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.
tscale(x,y)
tscale(x,y)
x |
A numeric value. |
y |
A numeric matrix or a numeric vector. |
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.
Returns the scaled Y
.
x<-5 y<-matrix(c(2,3,5,7),ncol=2,nrow=2) tscale(x,y) y<-c(1,2,3) tscale(x,y)
x<-5 y<-matrix(c(2,3,5,7),ncol=2,nrow=2) tscale(x,y) y<-c(1,2,3) tscale(x,y)
This function add two or more vectors and returns the resultant vector. This function works only if vectors are of same length.
tvectorAdd(...)
tvectorAdd(...)
... |
Any number of numeric vectors. |
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.
Returns tropical sum of argumented vectors.
x<-c(5,6,7) y<-c(1,2,3) tvectorAdd(x,y)
x<-c(5,6,7) y<-c(1,2,3) tvectorAdd(x,y)
This function multiplies two or more vectors and returns the resultant vector. This function works only if vectors are of same length.
tvectorMultiply(...)
tvectorMultiply(...)
... |
Any number of numeric vectors. |
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.
Returns the product of argumented vectors.
x<-c(5,6,7) y<-c(1,2,3) tvectorMultiply(x,y)
x<-c(5,6,7) y<-c(1,2,3) tvectorMultiply(x,y)
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.
tvectotMatrixProduct(Y,x)
tvectotMatrixProduct(Y,x)
Y |
A numeric matrix. |
x |
A numeric vector. |
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.
Returns the tropical product of vectror x
and matrix Y
.
x<-c(1,2,3) Y<-matrix(c(1,2,3,4,5,6,1,2,3), nrow = 3, ncol = 3) tvectotMatrixProduct(Y,x)
x<-c(1,2,3) Y<-matrix(c(1,2,3,4,5,6,1,2,3), nrow = 3, ncol = 3) tvectotMatrixProduct(Y,x)