Multiply matrix numeric with matrix no numeric


Please help,

Do you know of any package or mathematical library for handling alphanumeric variables?

I explain what I try to do is multiply matrix numeric with matrix no numeric.

Example (done with the software TI-Nspire):


The code in R is:

y <- c( 26.5, 28.1, 25.2, 26.0, 24.0)

xmain <- c(0.040, 0.041, 0.055, 0.056, 0.062)
x1 <- rep(1,length(xmain))

b <- c("b0","b1")

mx<- cbind(x1,xmain)

ei <- y - (mx %*% b)

The error message is:
Error in mx %*% b : requires numeric/complex matrix/vector arguments

I hope you can help me,


@apereira95 : What is that you will achieve by creating a alpha-numeric matrix?

As per my knowledge, this is not directly achievable in R. You will have to write your own chunk of code defining the conditions and then the output.


What happens why you try to multiply a number by a character string?

IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: "b0" * 5
Out[1]: 'b0b0b0b0b0'

But in R

> "b0" * 5
Error in "b0" * 5 : non-numeric argument to binary operator

The %*% operator in your (mx %*% b) is giving the same complaint, because b is a list of two characters, which, of course are non-numeric. Matrices have to be all numeric or all character, so it stands to reason that their combinations do, as well.

The key, I think, lies in misunderstanding the third term in the image

See what happens if you turn those into numeric variables:

b0 <- as.matrix(pi)
b1 <- as.matrix(2.71828)
b <- rbind(b0,b1)
1 Like

I belive you are looking for a Computer Algebra System (like the one your calculator uses) for R, you can take a look into
ryacas or rsympy


Thanks Technocrat, but my goal is to obtain a matrix of expressions. Applying the indicated, I obtain a numerical matrix with the results

Next time, you'll get better answers with a reproducible example, called a reprex . @adrersrcs suggestion seems like a good one

Yes, thanks for the quotation

Heramb. My objective is to obtain a matrix of expressions to then apply and solve a system of equations.

I'm working to make an algorithm that presents a set of ordered pairs apply a least squares adjustment that looks for a polynomial of degree and that better fit in the set of ordered pairs.

I was thinking about doing it with a matrix approach. But more than solving the problem, I look for a tool that allows me to handle these concepts of algebra in R that are very important in engineering.


You are trying to perform a linear regression using linear algebra. Doing this kind of exercise it is always educational, but if you are more focused on exploring the applications of linear algebra, maybe you want to use a different tool for the job, like Matlab for example, because actually these concepts are more important while you are studying engineering than they are in real life scenarios.

1 Like

Thanks @andresrcs! Yes, this problem has already been solved with Matlab. Now I want to try solving it with R.

Your answers have been very useful for what I am studying.

Your welcome @apereira95, it's always nice being able to help an engineer colleague, even more if he's latinamerican like myself.

1 Like

To see what’s already out there along these lines, you might want to take a look at the Numerical Mathematics task view on CRAN.

1 Like

Those resources are for numerical linear algebra, he is interested in symbolic linear algebra although, it doesn't hurt to read them :slightly_smiling_face:

Yes, I know, but despite the name of the Task View, there are packages that do symbolic algebra discussed in there anyway. But I agree that I should have made it clearer that that’s an imperfect starting point (I’d love to know of a better one! Symbolic math in R is a rather esoteric topic thus far).

I agree with that, even my old hp 50g calculator has better support for programming with symbolic algebra than R, not the best tool for the job.

Thanks @jcblum the infomations is very useful. Used Python and Matlab Interfaces
can be managed symbolic linear algebra.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.