[R] Treating variables as symbols
Hey, I'm trying to find how to perform operations with a variable treated as a symbol. For, an extremely simple, example I want to integrate a*x with respect to x and I want to find the indefinite integral of this, (a*x^2/2), or the definite integral with some interval for x. Another example of such a use would be to create a function y-function(x) {a*x} and by typig y(2) I would get the result 2*a Is there a way to treat variables as merely symbols? Any help much appreciated -M [[alternative HTML version deleted]] __ R-help@r-project.org 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.
Re: [R] Treating variables as symbols
Hi Zemajik, Try this: y - function(a) paste(a, '*x', sep=) y(2) [1] 2*x Also, take a look at the Ryacas package. HTH, Jorge On Thu, Oct 1, 2009 at 9:46 AM, ZeMajik wrote: Hey, I'm trying to find how to perform operations with a variable treated as a symbol. For, an extremely simple, example I want to integrate a*x with respect to x and I want to find the indefinite integral of this, (a*x^2/2), or the definite integral with some interval for x. Another example of such a use would be to create a function y-function(x) {a*x} and by typig y(2) I would get the result 2*a Is there a way to treat variables as merely symbols? Any help much appreciated -M [[alternative HTML version deleted]] __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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.
Re: [R] Treating variables as symbols
Try this: y - function(a) substitute(a * x, list(a = a)) On Thu, Oct 1, 2009 at 10:46 AM, ZeMajik zema...@gmail.com wrote: Hey, I'm trying to find how to perform operations with a variable treated as a symbol. For, an extremely simple, example I want to integrate a*x with respect to x and I want to find the indefinite integral of this, (a*x^2/2), or the definite integral with some interval for x. Another example of such a use would be to create a function y-function(x) {a*x} and by typig y(2) I would get the result 2*a Is there a way to treat variables as merely symbols? Any help much appreciated -M [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org 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.
Re: [R] Treating variables as symbols
Thanks guys, Ryacas is pretty much what I'm looking for!However, I can't seem to get it to work properly. For example: yacas(Integrate(x) x) Error in parse(text = text, srcfile = NULL) : unexpected numeric constant in / (^ (x ,2 2 Same thing with expressions such as yacas(x*x) However yacas(2*2) expression(4) So it seems there is a successful connection between yacas and R. I didn't find any info on the problem by googling it unfortunately! Any ideas what it might be? Thanks again, M On Thu, Oct 1, 2009 at 3:50 PM, Jorge Ivan Velez jorgeivanve...@gmail.comwrote: Hi Zemajik, Try this: y - function(a) paste(a, '*x', sep=) y(2) [1] 2*x Also, take a look at the Ryacas package. HTH, Jorge On Thu, Oct 1, 2009 at 9:46 AM, ZeMajik wrote: Hey, I'm trying to find how to perform operations with a variable treated as a symbol. For, an extremely simple, example I want to integrate a*x with respect to x and I want to find the indefinite integral of this, (a*x^2/2), or the definite integral with some interval for x. Another example of such a use would be to create a function y-function(x) {a*x} and by typig y(2) I would get the result 2*a Is there a way to treat variables as merely symbols? Any help much appreciated -M [[alternative HTML version deleted]] __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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.
Re: [R] Treating variables as symbols
Read the troubleshooting section on the home page: http://ryacas.googlecode.com Note, in particular, that it currently only works with an older version of the XML package. library(Ryacas) packageDescription(XML)$Version [1] 1.96-0 x - Sym(x) Integrate(x*x, x) [1] Starting Yacas! expression(x^3/3) On Thu, Oct 1, 2009 at 11:08 AM, ZeMajik zema...@gmail.com wrote: Thanks guys, Ryacas is pretty much what I'm looking for!However, I can't seem to get it to work properly. For example: yacas(Integrate(x) x) Error in parse(text = text, srcfile = NULL) : unexpected numeric constant in / (^ (x ,2 2 Same thing with expressions such as yacas(x*x) However yacas(2*2) expression(4) So it seems there is a successful connection between yacas and R. I didn't find any info on the problem by googling it unfortunately! Any ideas what it might be? Thanks again, M On Thu, Oct 1, 2009 at 3:50 PM, Jorge Ivan Velez jorgeivanve...@gmail.comwrote: Hi Zemajik, Try this: y - function(a) paste(a, '*x', sep=) y(2) [1] 2*x Also, take a look at the Ryacas package. HTH, Jorge On Thu, Oct 1, 2009 at 9:46 AM, ZeMajik wrote: Hey, I'm trying to find how to perform operations with a variable treated as a symbol. For, an extremely simple, example I want to integrate a*x with respect to x and I want to find the indefinite integral of this, (a*x^2/2), or the definite integral with some interval for x. Another example of such a use would be to create a function y-function(x) {a*x} and by typig y(2) I would get the result 2*a Is there a way to treat variables as merely symbols? Any help much appreciated -M [[alternative HTML version deleted]] __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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. __ R-help@r-project.org 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.