0
max <- 0

    for(i in 1:1000){
        x1 <- runif(1:10, 1)
        x2 <- runif(1:10, 1)
        x3 <- runif(1:10, 1)
        z <- (exp(x1)+x2)^2 + (3(1-x3)^2)
        if(z > max)
            max <- z
    }
print(max)

This has to print maximum number between 1 to 10000 and 'z' is the formula.
I am getting error "Error: attempt to apply non-function".

2
Contributors
2
Replies
19
Views
3 Years
Discussion Span
Last Post by mical700
0
3(1-x3)

This is interpreted as "call the function 3 with the argument 1-x3" and since 3 isn't a function, you get that error message. I assume you simply forgot a * there.

0

Thanks' sepp2k. I appreciate. That multiplication cause me lot of pain. Thanks'

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.