# Problems dealing with matrices

12 messages
Open this post in threaded view
|

## Problems dealing with matrices

 Dear R-friends, Hope you doing well. I've been trying to deal with the following problem for the couple of days but couldn't come up with a solution. It would be great if any of you could give some insight into it. I have three matrices like: dcvol<-matrix(c(0.13,0.61,0.25,0.00,0.00,0.00,0.52,0.37,0.09,0.00,0.00,0.00,                 0.58,0.30,0.11,0.00,0.00,0.00,0.46,0.22,0.00,0.00,0.00,0.00,                 0.09),nrow=5,ncol=5) volinp<-matrix(c(100,0,0,0,0),nrow=5,ncol=1) scvol<-matrix(c(1:40),nrow=5,ncol=8) What I essentially want to do is to add each value in scvol[1,] with the volinp[1,1] and then multiply each new volinp with dcvol and finally put the outputs in a new matrix. Thanks in advance. Halim                 --------------- Md. Abdul Halim Assistant Professor Department of Forestry and Environmental Science Shahjalal University of Science and Technology,Sylhet-3114, Bangladesh. Cell: +8801714078386. alt. e-mail: [hidden email] -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Problems dealing with matrices

 Hi Arun, Thank you very much for your response. Sorry, if I couldn't explain clearly. I think, I should restate the problem to get exactly what I want. Here it goes: I have 2 matrices and 1 vector, namely, dcmat<-matrix(c(0.13,0.61,0.25,0.00,0.00,0.00,0.52,0.37,0.09,0.00,0.00,0.00,                 0.58,0.30,0.11,0.00,0.00,0.00,0.46,0.22,0.00,0.00,0.00,0.00,                 0.09),nrow=5,ncol=5) volmat<-matrix(c(100,0,0,0,0),nrow=5,ncol=1) volinp<-c(1:40) What I essentially want to do is to multiply 'dcmat' with 'volmat' and dump the output in a new matrix 'vol'. But before that, in the first step, I want to add volinp[1] with volmat[1,1]. So, the first column of the output matrix 'vol' matrix will be:         [,1] [1,]   13.13 [2,]   61.61 [3,]   25.25 [4,]    0.00 [5,]    0.00 In the 2nd step, I want to add vol[1,1] with volinp[2]. and replace this value with volmat[1,1]. The new 'volmat' will look like:        [,1] [1,]   15.13 [2,]    0.00 [3,]    0.00 [4,]    0.00 [5,]    0.00 And then multiply 'dcmat' with the new 'volmat', and the 2nd column of output matrix 'vol' will look like:        [,2] [1,] 1.9669 [2,] 9.2293 [3,] 3.7825 [4,] 0.0000 [5,] 0.0000 Then again, replace the volmat[1,1] with vol[1,2] + volinp[3] and multiply the new 'volmat' with 'dcmat'. This addition, multiplication, and dumping will continue up to the length of 'volinp' and the final output matrix 'vol' will be something like:       [,1]    [,2]      [,3]  ...length(volinp) [1,] 13.13  1.9669  0.645697  ... [2,] 61.61  9.2293  3.029809  ... [3,] 25.25  3.7825  1.241725  ... [4,]  0.00  0.0000  0.000000  ... [5,]  0.00  0.0000  0.000000  ...   Within my limited capacity, I've tried to come up with a solution but failed. I'll appreciate your/others' help with gratefulness. Regards, Halim --------------- Md. Abdul Halim Assistant Professor Department of Forestry and Environmental Science Shahjalal University of Science and Technology,Sylhet-3114, Bangladesh. Cell: +8801714078386. alt. e-mail: [hidden email]   On Sat, 23 Nov 2013 14:10:12 -0800 (PST), arun wrote > Hi, > Could you show your expected output?  It is a bit unclear from the description. > > On Saturday, November 23, 2013 2:00 PM, halim10-fes [hidden email]> wrote: Dear R-friends, > > Hope you doing well. I've been trying to deal with the following > problem for the couple of days but couldn't come up with a solution. > It would be great if any of you could give some insight into it. > > I have three matrices like: > > dcvol<-matrix(c(0.13,0.61,0.25,0.00,0.00,0.00,0.52,0.37,0.09,0.00, > 0.00,0.00,                 0.58,0.30,0.11,0.00,0.00,0.00,0.46,0.22, > 0.00,0.00,0.00,0.00,                 0.09),nrow=5,ncol=5) volinp<- > matrix(c(100,0,0,0,0),nrow=5,ncol=1) > > scvol<-matrix(c(1:40),nrow=5,ncol=8) > > What I essentially want to do is to add each value in scvol[1,] with > the volinp[1,1] and then multiply each new volinp with dcvol and > finally put the outputs in a new matrix. > > Thanks in advance. > > Halim                > --------------- > Md. Abdul Halim > Assistant Professor > Department of Forestry and Environmental Science > Shahjalal University of Science and Technology,Sylhet-3114, > Bangladesh. > Cell: +8801714078386. > alt. e-mail: [hidden email] > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Problems dealing with matrices

 In reply to this post by halim10-fes Please apologize me! Earlier I've sent a message erroneously. Following is the original problem for which I'm seeking help. Extremely sorry...   Hi Arun, Thank you very much for your response. Sorry, if I couldn't explain clearly. I think, I should restate the problem to get exactly what I want. Here it goes: I have 2 matrices and 1 vector, namely, dcmat<-matrix(c(0.13,0.61,0.25,0.00,0.00,0.00,0.52,0.37,0.09,0.00,0.00,0.00,                 0.58,0.30,0.11,0.00,0.00,0.00,0.46,0.22,0.00,0.00,0.00,0.00,                 0.09),nrow=5,ncol=5) volmat<-matrix(c(100,0,0,0,0),nrow=5,ncol=1) volinp<-c(1:40) What I essentially want to do is to multiply 'dcmat' with 'volmat' and dump the output in a new matrix 'vol'. But before that, in the first step, I want to add volinp[1] with volmat[1,1]. So, the first column of the output matrix 'vol' matrix will be:         [,1] [1,]   13.13 [2,]   61.61 [3,]   25.25 [4,]    0.00 [5,]    0.00 In the 2nd step, I want to replace 'volmat' with vol[,1] and add volinp[2] with vol[1,1]. The new 'volmat' will look like:         [,1] [1,]   15.13 [2,]   61.61 [3,]   25.25 [4,]    0.00 [5,]    0.00 Then multiply 'dcmat' with the new 'volmat', and the 2nd column of output matrix 'vol' will look like:         [,2] [1,]  1.9669 [2,] 41.2665 [3,] 41.2232 [4,] 13.1199 [5,]  2.7775 Then again, replace the 'volmat' with vol[,2], add volinp[3] with vol[1,2] and multiply the new 'volmat' with 'dcmat'. This replacement, addition, multiplication, and dumping will continue up to the length of 'volinp' and the final output matrix 'vol' will be something like:       [,1]    [,2]      [,3]    ...length(volinp) [1,] 13.13   1.9669   0.645697  ... [2,] 61.61  41.2665  24.488389  ... [3,] 25.25  41.2232  40.419786  ... [4,]  0.00  13.1199  22.116099  ... [5,]  0.00   2.7775   7.670905  ...   Within my limited capacity, I've tried to come up with a solution but failed. I'll appreciate your/others' help with gratefulness. Regards, Halim --------------- Md. Abdul Halim Assistant Professor Department of Forestry and Environmental Science Shahjalal University of Science and Technology,Sylhet-3114, Bangladesh. Cell: +8801714078386. alt. e-mail: [hidden email]   On Sat, 23 Nov 2013 14:10:12 -0800 (PST), arun wrote > Hi, > Could you show your expected output?  It is a bit unclear from the description. > > On Saturday, November 23, 2013 2:00 PM, halim10-fes [hidden email]> wrote: Dear R-friends, > > Hope you doing well. I've been trying to deal with the following > problem for the couple of days but couldn't come up with a solution. > It would be great if any of you could give some insight into it. > > I have three matrices like: > > dcvol<-matrix(c(0.13,0.61,0.25,0.00,0.00,0.00,0.52,0.37,0.09,0.00, > 0.00,0.00,                 0.58,0.30,0.11,0.00,0.00,0.00,0.46,0.22, > 0.00,0.00,0.00,0.00,                 0.09),nrow=5,ncol=5) volinp<- > matrix(c(100,0,0,0,0),nrow=5,ncol=1) > > scvol<-matrix(c(1:40),nrow=5,ncol=8) > > What I essentially want to do is to add each value in scvol[1,] with > the volinp[1,1] and then multiply each new volinp with dcvol and > finally put the outputs in a new matrix. > > Thanks in advance. > > Halim                > --------------- > Md. Abdul Halim > Assistant Professor > Department of Forestry and Environmental Science > Shahjalal University of Science and Technology,Sylhet-3114, > Bangladesh. > Cell: +8801714078386. > alt. e-mail: [hidden email] > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Problems dealing with matrices

 I think the following is a pretty literal translation from your description. Looks like a linear difference equation with a ramp forcing function. wt <- matrix( c(1,0,0,0,0 ), nrow=5 ) vol <- matrix( NA, nrow=5, ncol=length( volinp ) ) vol[ , 1 ] <- dcmat %*% ( volmat + wt ) for ( idx in volinp[ -1 ] ) {    vol[ , idx ] <- dcmat %*% ( vol[ , idx-1 ] + idx * wt ) } On Sun, 24 Nov 2013, halim10-fes wrote: > > Please apologize me! Earlier I've sent a message erroneously. Following is the > original problem for which I'm seeking help. Extremely sorry... > > > Hi Arun, > > Thank you very much for your response. Sorry, if I couldn't explain clearly. I > think, I should restate the problem to get exactly what I want. Here it goes: > > I have 2 matrices and 1 vector, namely, > > dcmat<-matrix(c(0.13,0.61,0.25,0.00,0.00,0.00,0.52,0.37,0.09,0.00,0.00,0.00, >                0.58,0.30,0.11,0.00,0.00,0.00,0.46,0.22,0.00,0.00,0.00,0.00, >                0.09),nrow=5,ncol=5) > > volmat<-matrix(c(100,0,0,0,0),nrow=5,ncol=1) > > volinp<-c(1:40) > > What I essentially want to do is to multiply 'dcmat' with 'volmat' and dump > the output in a new matrix 'vol'. But before that, in the first step, I want > to add volinp[1] with volmat[1,1]. So, the first column of the output matrix > 'vol' matrix will be: > >        [,1] > [1,]   13.13 > [2,]   61.61 > [3,]   25.25 > [4,]    0.00 > [5,]    0.00 > > In the 2nd step, I want to replace 'volmat' with vol[,1] and add volinp[2] > with vol[1,1]. The new 'volmat' will look like: > >        [,1] > [1,]   15.13 > [2,]   61.61 > [3,]   25.25 > [4,]    0.00 > [5,]    0.00 > > Then multiply 'dcmat' with the new 'volmat', and the 2nd column of output > matrix 'vol' will look like: > >        [,2] > [1,]  1.9669 > [2,] 41.2665 > [3,] 41.2232 > [4,] 13.1199 > [5,]  2.7775 > > Then again, replace the 'volmat' with vol[,2], add volinp[3] with vol[1,2] and > multiply the new 'volmat' with 'dcmat'. This replacement, addition, > multiplication, and dumping will continue up to the length of 'volinp' and the > final output matrix 'vol' will be something like: > >      [,1]    [,2]      [,3]    ...length(volinp) > [1,] 13.13   1.9669   0.645697  ... > [2,] 61.61  41.2665  24.488389  ... > [3,] 25.25  41.2232  40.419786  ... > [4,]  0.00  13.1199  22.116099  ... > [5,]  0.00   2.7775   7.670905  ... > > Within my limited capacity, I've tried to come up with a solution but failed. > > I'll appreciate your/others' help with gratefulness. > > Regards, > > Halim > > --------------- > Md. Abdul Halim > Assistant Professor > Department of Forestry and Environmental Science > Shahjalal University of Science and Technology,Sylhet-3114, > Bangladesh. > Cell: +8801714078386. > alt. e-mail: [hidden email] > > On Sat, 23 Nov 2013 14:10:12 -0800 (PST), arun wrote >> Hi, >> Could you show your expected output?  It is a bit unclear from the > description. >> >> On Saturday, November 23, 2013 2:00 PM, halim10-fes > [hidden email]> wrote: Dear R-friends, >> >> Hope you doing well. I've been trying to deal with the following >> problem for the couple of days but couldn't come up with a solution. >> It would be great if any of you could give some insight into it. >> >> I have three matrices like: >> >> dcvol<-matrix(c(0.13,0.61,0.25,0.00,0.00,0.00,0.52,0.37,0.09,0.00, >> 0.00,0.00,                 0.58,0.30,0.11,0.00,0.00,0.00,0.46,0.22, >> 0.00,0.00,0.00,0.00,                 0.09),nrow=5,ncol=5) > volinp<- >> matrix(c(100,0,0,0,0),nrow=5,ncol=1) >> >> scvol<-matrix(c(1:40),nrow=5,ncol=8) >> >> What I essentially want to do is to add each value in scvol[1,] with >> the volinp[1,1] and then multiply each new volinp with dcvol and >> finally put the outputs in a new matrix. >> >> Thanks in advance. >> >> Halim                >> --------------- >> Md. Abdul Halim >> Assistant Professor >> Department of Forestry and Environmental Science >> Shahjalal University of Science and Technology,Sylhet-3114, >> Bangladesh. >> Cell: +8801714078386. >> alt. e-mail: [hidden email] >> >> -- >> This message has been scanned for viruses and >> dangerous content by MailScanner, and is >> believed to be clean. >> >> ______________________________________________ >> [hidden email] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html>> and provide commented, minimal, self-contained, reproducible code. > > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > --------------------------------------------------------------------------- Jeff Newmiller                        The     .....       .....  Go Live... DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...                                        Live:   OO#.. Dead: OO#..  Playing Research Engineer (Solar/Batteries            O.O#.       #.O#.  with /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k ---------------------------------------------------------------------------______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Problems dealing with matrices

Open this post in threaded view
|

## Re: Problems dealing with matrices

Open this post in threaded view
|

## Re: Problems dealing with matrices

Open this post in threaded view
|

## Re: Problems dealing with matrices

Open this post in threaded view
|

## Re: Problems dealing with matrices

Open this post in threaded view
|