Notices
Results 1 to 2 of 2

Thread: Defining Recursive formulas in R

  1. #1 Defining Recursive formulas in R 
    Forum Freshman
    Join Date
    Aug 2013
    Posts
    12
    Hello there, I'm very new to programming and as such have been facing quite a bit of difficulty with a current assignment. My goal is to define a recursive formula where x(i+1) is based on x(i) and u(i) where where u is a Gaussian (normal) variable. Because this is my first time doing this, however, I've decided to start simple and just try to construct a recursive formula based on x(i). Here's what I've got:

    y <- function(y) {
    + if(y==1)
    + return(1.5)
    + else
    + return(1.022*function(y-1))

    At which point I receive:
    Error: unexpected '-' in:
    "else
    return(1.022*function(y-"

    I've played around with the syntax so much and still I haven't been able to make it work. Any advice?


    Reply With Quote  
     

  2.  
     

  3. #2  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,670
    I am not really familiar with R but you appear to have named both the function and its parameter 'y'.

    Maybe you need:
    f <- function(y) { # function named f, withparameter y
    ...
    return(1.022*f(y-1) # call f with argument y-1
    }


    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

Similar Threads

  1. Diagram G and Recursive Transition Networks
    By invert_nexus in forum Mathematics
    Replies: 14
    Last Post: October 30th, 2013, 10:28 AM
  2. Recursive definition and induction principle
    By annitaz in forum Mathematics
    Replies: 1
    Last Post: March 9th, 2010, 02:00 PM
  3. Defining Entropy
    By organic god in forum Physics
    Replies: 3
    Last Post: January 13th, 2009, 07:47 AM
  4. Recursive formula
    By biohazard87 in forum Mathematics
    Replies: 9
    Last Post: December 10th, 2007, 11:42 PM
  5. Recursive enumerable set
    By nico2005 in forum Mathematics
    Replies: 0
    Last Post: July 18th, 2005, 08:11 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •