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$

closed as unclear what you're asking by MarcoB, m_goldberg, user9660, ubpdqn, Jens May 6 '16 at 15:51

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\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.