logo
down
shadow

Symbolic matrix mutiplication error (Ryacas)


Symbolic matrix mutiplication error (Ryacas)

Content Index :

Symbolic matrix mutiplication error (Ryacas)
Tag : r , By : T11M
Date : November 26 2020, 04:01 AM

it should still fix some issue Firstly, to multiply Ryacas matrices you want aa * aa rather than aa %*% aa. But that alone doesn't help in your case as conv.mat doesn't give exactly what we need (an expression).
We may use, e.g.,
conv.mat <- function(x)
  do.call(List, lapply(1:nrow(x), function(r) do.call(List, as.list(x[r, ]))))
M <- matrix(c(1, 2, 3, 7), 2, byrow = TRUE)
M %*% M
#      [,1] [,2]
# [1,]    7   16
# [2,]   24   55
M <- conv.mat(M)
M * M
# expression(list(list(7, 16), list(24, 55)))

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Evaluate a symbolic Ryacas expression


Tag : r , By : Cadu
Date : March 29 2020, 07:55 AM
will be helpful for those in need G.Grothendieck pointed out in comments that you'll need to first to capture the expression to be operated upon below:
soln <- Solve(n/2*(2-exp(-lambda12*Tf)-exp(-lambda18*Tf))==d , n) 
X <- yacas(soln)$text
 X <- expression(list(n == 382/1.625))
 res <- eval(X[[1]][[2]][[3]])
 res
 [1] 235.0769
as.list(X)
# [[1]]
# list(n == 382/1.625)

as.list(X[[1]])
# [[1]]
# list
# 
# [[2]]
# n == 382/1.625

as.list(X[[1]][[2]])
# [[1]]
# `==`
# 
# [[2]]
# n
# 
# [[3]]
# 382/1.625

matrix chain mutiplication dynamic programming


Tag : algorithm , By : lifchicker
Date : March 29 2020, 07:55 AM
around this issue First of all, it's pseudocode, and these arrays are 1-based. If you are using a C-like language, that will probably be the first issue, since arrays in C start at index 0 and end at len-1, if len is the length of array. Next, the variable n is chosen to be smaller than the total number of matrices by 1. If you replace n with p.length - 1, then it may also become a bit clearer what's going on.
L = 4;
for (i = 1; i <= p.length - 4; i++)
{
   ...
}
L = 4;
for (i = 1; i <= p.length - 4; i++)
{
    j = i + 3;
    ...
}
L = 4;
for (i = 1; i <= p.length - 4; i++)
{
    j = i + 3;
    m[i,j] = MAXINT;
    for (k = i; k <= j - 1; k++)
    { 
        // get the cost of splitting at `k`, 
        // i.e. chains (i, k) and (k + 1, j)
    }
}

symbolic matrix multiplication by Ryacas


Tag : r , By : Tony Siu
Date : March 29 2020, 07:55 AM
may help you . I define two matrices mat1 and mat2 in Sym class which is suitable for Ryacas symbolic computation: , Try this:
> mat1 * mat2
expression(list(list(x^2 + 6, x^2 + 12 * x), list(x^4 + 3 * x, 
    x^4 + 6 * x^2)))

Element-wise mutiplication .* of vectors gives matrix in Matlab


Tag : matlab , By : user184406
Date : March 29 2020, 07:55 AM
will help you Due to implicit expansion (introduced in 2016b) it's essentially the same as using bsxfun.
But what does that mean?
a = 1:3;
b = 2:4;
c = a.*b; 
% c = [2 6 12], element-wise multiplication c(j) = a(j)*b(j)

c = b'*a;  
% c = [2 4 5; 3 6 9; 4 8 12]
% standard matrix multiplication of vectors
% c(i,j) = a(i) + b(j)

c = bsxfun(@times, b', a)
% c = [2 4 5; 3 6 9; 4 8 12]
% bsxfun applies the function (in this case @times) to b' and a
 % b' in singleton in the 2nd dimension, a is singleton in the 1st dimension
 % Use repmat to perform the expansion to the correct size
 repmat(b', 1, size(a,2)) .* repmat(a, size(b',1), 1)
 % Equivalent to...
 repmat(b', 1, 3) .* repmat(a, 3, 1)
 % Equivalent to...
 [2 2 2; 3 3 3; 4 4 4] .* [1 2 3; 1 2 3; 1 2 3]   
 % = [2 4 5; 3 6 9; 4 8 12] the same as b'*a
c = a.*b'; % Error: Matrix dimensions must agree.
c = b'.*a; % Error: Matrix dimensions must agree.
c = a.*b'; % [2 4 5; 3 6 9; 4 8 12] the same as bsxfun(@times, a, b')
c = b'.*a; % [2 4 5; 3 6 9; 4 8 12] the same as bsxfun(@times, b', a)
% These two are equivalent also because order of operations is irrelevant
% We can see this by thinking about the expansion discussed above
c = a(:).*b(:); % c = [2; 6; 12] always a column vector

Symbolic computation in R with Ryacas - results become character


Tag : r , By : Boris
Date : March 29 2020, 07:55 AM
may help you . I have a small MATLAB script mainly doing derivatives using symbolic toolbox that I want to rewrite into R. I chose Ryacas package because I found rSymPy too tricky to install... Here is my R code , There are several problems with the R code in the question:
typeof(NA)
## [1] "logical"
f <- matrix(list(), 4, 4)
f[[1, 1]] <- z^2 * exp(-z) / (1 - exp(-z))
psi <- list()
psi[[1]] <- z^2 * exp(-z) / (1 - exp(-z))
Eval(f[[i, 1]], list(z = 1))
## [1] 0.2432798
z <- 1
Eval(f[[i, 1]])
vignette("Ryacas")
demo(package = "Ryacas")
# install.packages('Ryacas')
library(Ryacas)    

z <- Sym("z")

psi <- list()
psi[[1]] <- z^2 * exp(-z) / (1 - exp(-z))
psi[[2]] <- z^2 * exp(-z) / (1 - exp(-z)) * log(z)
psi[[3]] <- z^2 * exp(-z) / (1 - exp(-z)) * log(z)^2

f <- matrix(list(), 4, 4)
f[[1,1]] <- z^2 * exp(-z) / (1 - exp(-z))
for(i in 2:4) {
  f[[i, 1]] <- deriv(psi[[i-1]], z)
  j <- 2
  while(j <= i) {
    f[[i, j]] <- deriv(f[[i, j-1]] / f[[j-1, j-1]], z)
    j <- j + 1
  }
}

i <- 2
deriv(psi[[i-1]], z)
f[[i, 1]]

Eval(f[[i, 1]], list(z = 1))
Related Posts Related QUESTIONS :
  • Generating the sequence 111122222333334
  • Unable to use has_goog_key() in R
  • how to multiply each row with a scaler in corresponding column?
  • R is not recognizing levels of a factor as the same. Is there a way to do this?
  • Calculating mean of replicate experiment result values in a column based on multiple columns using R
  • Best method to extract the first instance of a string between specified keywords using data.table
  • ignore optional combination of alphanumeric characters in str_extract
  • Why tracemem shows two copies when modification occurs inside function body?
  • Can't use mppm on multitype point patterns
  • How to move selected matrix rows to top of matrix based on a selection vector of row names
  • Combining expressions with a common operator
  • Passing string through multiple filters for matching
  • Convert two columns in R to rows of unique occurrence
  • How to create a dataframe using a function based on user-input?
  • How to access the visited vertices in a given shortest path using R igraph
  • Differences in Unicode character output with print()
  • Extracting Function or Objects from a String and then Piping Them with Magrittr/Dplyr
  • renderUI not evaluated until it is rendered
  • Find the maximum absolute value by row in an R data frame
  • Extracting data from irregular lists using purrr:map()
  • transforming data based on range of column in r
  • Identify and subset rows with some similar information
  • converting character from mongolite to timestamp in R
  • Create list from two vectors with every combo of each
  • Error in running a spread because of unique 'key combinations'; combining rows of data
  • visualize numerical strings as a matrixed heatmap
  • how to make a blocked matrix?
  • How to summarize with two functions using with dplyr
  • Dataframe is no longer the same after being saved to Excel and read back in
  • Create duplicate rows using based on availability of data
  • Keep empty groups when grouping with data.table in R
  • Grouping of Event Time Data based on multiple, iterative conditions
  • Formatting Numbers in Flextable for Specific Columns
  • How to store results from for-loop into a dataframe
  • How to select the values in my dataframe which has logical operator "<" (less than), divide them by two, an
  • Rowwise extract data between two strings
  • Convert a string separate by . and +
  • stacking function for values in R
  • dplyr coerces characters to factors
  • How do I use spread and group_by on a single row dataset
  • Replacing values in one matrix with values from another
  • Aggregate data and exclude duplicates in one column
  • Perform an R data.table binary search with OR select
  • How can I include a function in the Standard Deviation parameter of pnorm
  • How to get a tidy excel output of P values from R
  • Rotate boxplot legend (R, ggplot2)
  • dplyr::n() returns “Error: Error: n() should only be called in a data context ”
  • Extract fix columns and one variable column from a list of df´s in R
  • A function that can translate DNA sequence to binary code
  • I want to extract 365 netcdf files using loop
  • rvest vs RSelenium results for text extracting
  • Converting wide data to tall data
  • How to remove vertical white lines when using ggsave in R?
  • R-Shiny error: "renderDataTable" and "server=FALSE"
  • Read csv file with selected rows using data.table's fread
  • how to resolve an error like non numeric argument to binary argument?
  • If value exists in environment
  • R get one value according to some rules in each group
  • Use any apply method to find difference between max and min score for each students
  • subsetting a dataframe by existing object
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com