In order to define a function f as:

> f <- function(x) (x+1)*(x+2)

I want to use the notation:

> v = c(1,2)
> g <- function(x) prod((v+x))

That apparently works and, for instance,
the loop:

>for (i in 1:100) {  print(f(i)-g(i)) }

Produces a sequence of zeros.

Nevertheless, if I try to plot
the function g by:

>t = seq(0,100,1)
>plot(t,g(t),type="l")

I obtain the following errors/warning:

> Error in xy.coords(x, y, xlabel, ylabel, log) : 
>        'x' and 'y' lengths differ
>In addition: Warning message:
>longer object length
>        is not a multiple of shorter object length in: v + x 
>Execution halted

Any idea about that?

Kind regards,
Alessandro


-- 
============================================================
Alessandro Antonucci
Dalle Molle Institute for Artificial Intelligence (IDSIA)
at Idsia                        e-mail: [EMAIL PROTECTED]
Galleria 2                      web:   idsia.ch/~alessandro
Via Cantonale                   mobile:   +39 339-567-23-28
CH-6928                         tel:       +41 58-666-66-69
Manno - Lugano                  fax:       +41 58-666-66-61
Switzerland                     skype: alessandro.antonucci

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to