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".

Recommended Answers

All 2 Replies

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.