curve

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

curve

Dwayne Blind
Dear R users,

How can I use "curve" with a function of two variables ?

Thank you very much,
Dwayne

        [[alternative HTML version deleted]]

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: curve

Ben Bolker
Dwayne Blind <dwayneblind <at> gmail.com> writes:

> How can I use "curve" with a function of two variables ?

see "curve3d" in the emdbook package.

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: curve

Duncan Murdoch
In reply to this post by Dwayne Blind
On 14/04/2010 4:59 PM, Dwayne Blind wrote:
> Dear R users,
>
> How can I use "curve" with a function of two variables ?
>  

See Ben Bolker's reply if you want to plot a surface.  If you want to
plot a curve by holding one of the two variables fixed, just set it to a
constant value, and use "x" as the other variable, e.g.

f <- function(x, y) { x^2 + y^2 }

curve(f(x, 2), from= .... )

curve(f(3, x), from= .... )

or wrap the function in a one variable function if you want to follow
some complicated path, e.g.

curve(function(t) f(t, t^2), from=....)

Duncan Murdoch

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: curve

Greg Snow-2
Or here is a way to plot against one of the variables while interactively changing the other one:

library(TeachingDemos)

myfun <- function(x,y) sin(x^2) * cos(y^2)

myfun2 <- function(y) curve( myfun(x,y), from=-pi, to=pi, ylim=c(-1,1) )

tkexamp( myfun2,
        list( y=list('slider', from=-pi, to=pi, resolution=2*pi/50, init=0) ) )



--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Duncan Murdoch
> Sent: Thursday, April 15, 2010 7:29 AM
> To: Dwayne Blind
> Cc: [hidden email]
> Subject: Re: [R] curve
>
> On 14/04/2010 4:59 PM, Dwayne Blind wrote:
> > Dear R users,
> >
> > How can I use "curve" with a function of two variables ?
> >
>
> See Ben Bolker's reply if you want to plot a surface.  If you want to
> plot a curve by holding one of the two variables fixed, just set it to
> a
> constant value, and use "x" as the other variable, e.g.
>
> f <- function(x, y) { x^2 + y^2 }
>
> curve(f(x, 2), from= .... )
>
> curve(f(3, x), from= .... )
>
> or wrap the function in a one variable function if you want to follow
> some complicated path, e.g.
>
> curve(function(t) f(t, t^2), from=....)
>
> Duncan Murdoch
>
> ______________________________________________
> [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.

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: curve

Dwayne Blind
Thanks to all three of you

2010/4/15 Greg Snow <[hidden email]>

> Or here is a way to plot against one of the variables while interactively
> changing the other one:
>
> library(TeachingDemos)
>
> myfun <- function(x,y) sin(x^2) * cos(y^2)
>
> myfun2 <- function(y) curve( myfun(x,y), from=-pi, to=pi, ylim=c(-1,1) )
>
> tkexamp( myfun2,
>        list( y=list('slider', from=-pi, to=pi, resolution=2*pi/50, init=0)
> ) )
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> [hidden email]
> 801.408.8111
>
>
> > -----Original Message-----
> > From: [hidden email] [mailto:r-help-bounces@r-
> > project.org] On Behalf Of Duncan Murdoch
> > Sent: Thursday, April 15, 2010 7:29 AM
> > To: Dwayne Blind
> > Cc: [hidden email]
> > Subject: Re: [R] curve
> >
>  > On 14/04/2010 4:59 PM, Dwayne Blind wrote:
> > > Dear R users,
> > >
> > > How can I use "curve" with a function of two variables ?
> > >
> >
> > See Ben Bolker's reply if you want to plot a surface.  If you want to
> > plot a curve by holding one of the two variables fixed, just set it to
> > a
> > constant value, and use "x" as the other variable, e.g.
> >
> > f <- function(x, y) { x^2 + y^2 }
> >
> > curve(f(x, 2), from= .... )
> >
> > curve(f(3, x), from= .... )
> >
> > or wrap the function in a one variable function if you want to follow
> > some complicated path, e.g.
> >
> > curve(function(t) f(t, t^2), from=....)
> >
> > Duncan Murdoch
> >
>  > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-<http://www.r-project.org/posting->
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[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.