# Re: [R] symbolic matrix elements...

From: Evan Cooch <evan.cooch_at_cornell.edu>
Date: Mon 18 Sep 2006 - 18:13:58 GMT

Seems to work also - thanks!

Tony Plate wrote:
> If I construct the matrix by list()ing together the expressions rather
> than c()ing, then it works OK:
>
> > x <- matrix(list( expression(x3-5*x+4), expression(log(x2-4*x))))
> > x[1,1]
> [[1]]
> expression(x3 - 5 * x + 4)
>
> > x[[1,1]]
> expression(x3 - 5 * x + 4)
> > D(x[[1,1]], "x")
> -5
> >
>
> The reason c() doesn't work properly here might have something to do
> with it creating a language object of an unconventional type:
>
> > c( expression(x3-5*x+4), expression(log(x2-4*x)))
> expression(x3 - 5 * x + 4, log(x2 - 4 * x))
> > expression(x3-5*x+4)
> expression(x3 - 5 * x + 4)
> >
>
> Using list() with language objects is much safer if you just want to
> make lists of them.
>
> -- Tony Plate
>
> Evan Cooch wrote:
>>
>> Eik Vettorazzi wrote:
>>
>>> test=matrix(c( expression(x^3-5*x+4), expression(log(x^2-4*x))))
>>> works.
>>
>> Well, not really (or I'm misunderstanding). Your code enters fine (no
>> errors), but I can't access individual elements - e.g., test[1,1]
>> gives me an error:
>>
>> > test=matrix(c( expression(x^3-5*x+4), expression(log(x^2-4*x))))
>> > test[1,1]
>> Error: matrix subscripting not handled for this type
>>
>> Meaning...what?
>>
>>
>>> btw. you recieved an error because D expects an expression and you
>>> offered a list
>>
>>
>> OK - so why then are each of the elements identified as an expression
>> which I print out the vector? Each element is reported to be an
>> expression. OK, if so, then I remain puzzled as to how this is a 'list'.
>>
>> ______________________________________________
>> R-help@stat.math.ethz.ch 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.
>>
>
>

```--
----------------------------------------------------------------------
Evan Cooch                          e.mail: evan.cooch@cornell.edu
Department of Natural Resources     voice: 607-255-1368
Fernow Hall - Cornell University    FAX: 607-255-0349
Ithaca, NY    14853                 http://canuck.dnr.cornell.edu
----------------------------------------------------------------------
A small error in the beginning is a great one in the end.- St. Thomas Aquinas

______________________________________________
R-help@stat.math.ethz.ch 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.
```
Received on Tue Sep 19 05:25:13 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 18 Sep 2006 - 19:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.