Displaying 1 result from an estimated 1 matches for "output_txt".
2009 Oct 01
1
Using optimize with array variables
Hello,
I am trying to figure out how to use optimize() with array variables
as inputs. I have a for loop in the function definition:
SS <- function(int,slo,x,y){
for(i in 1:length(x)) ((int+slo*x[i])-y[i])^2->squares[i]
sum(squares)->>sum_squares
output_txt = c ("The sum of squares is", sum_squares)
print(output_txt, quote=FALSE)}
Even assuming I make x and y single-integer variables, for example:
optimize(SS, c(0,1), tol = 0.0001, x=1, y=1, slo=1)
I get the error:
Error in optimize(SS, c(0, 1), tol = 1e-04, x = 1, y = 1, slo = 1) :
in...