1
$\begingroup$

I have following array:

data = {x^2, 2*x^2, x^3};

And I must send it to the following function:

funct[x_,data_,y_]:=Module[{i,j,m,n,r},
n=Length[x];
m=Length[data[[x[[1]]]]];
r=Table[
Subscript[data[[x[[i]]]][[j]]],{i,n},{j,m}];
LinearSolve[Transpose[r].r,Transpose[r].y]
];

And running the function:

funct[x, data, y]

But I would like to avoid sending unnecessary parameter to the function. How can I declare and use an array directly in my function?

$\endgroup$
  • $\begingroup$ Your code as posted does not evaluate because Subscript[x, [[1]]] is not valid input. Could you try to correct that or describe how you entered it? $\endgroup$ – Mr.Wizard May 4 '16 at 18:25
  • $\begingroup$ ok, the code should be correct. "Copy" added additional tags, I don't know why. Thanks. $\endgroup$ – mathemaniac00 May 4 '16 at 18:28
  • 3
    $\begingroup$ funct[x_, y_] := Module[{data = {x^2, 2 x^2, x^3}, i, j, m, n, r},...] $\endgroup$ – Bob Hanlon May 4 '16 at 18:32

Browse other questions tagged or ask your own question.