0
$\begingroup$

I have a little question.

Let me define the function:

f[k_]:=k

So 'k' in the argument of 'f' is a blank variable.

Is there a way to define a part of array as a blank variable like:

g[x[1]_]:=x[1]

Note that x[1] is not previously defined.

For example if I write:

g[x_[i_]]:=x[i]

and if I write g[x[1]] the output is

x[1]

and it is correct.

But if I define

h1[x_[i_]?NumericQ]:=NIntegrate[y,{y,0,x[i]}]

and now I evaluate

NIntegrate[h1[x[1]],{x[1],0,1}]

I obtain error messages like (I post a figure for a more clear visulization): enter image description here

Thanks for any tips and helps.

$\endgroup$
4
  • 1
    $\begingroup$ This will not work. But could you elaborate a bit more your problem? $\endgroup$ Jan 14 at 11:21
  • $\begingroup$ @DanielHuber, I'm going to edit my question and I'll add more details $\endgroup$ Jan 14 at 15:55
  • $\begingroup$ @DanielHuber, I edit my answer, this is what I need. $\endgroup$ Jan 14 at 16:16
  • $\begingroup$ You have not explained why you want dummy variables, in the function definition or the integral, to be indexed variables. $\endgroup$ Jan 14 at 16:34
0
$\begingroup$

If I understand what you are trying to do, observe that dummy variables can be anything, including indexed variables. To be concrete, if you define your h1 using "z":

h1[z_?NumericQ] := NIntegrate[y, {y, 0, z}];
y[k] := k^2;

Then for defined y, you can write:

NIntegrate[h1[x[i]], {x[i], 0, 1}]

and it returns a numerical value. Here the dummy variable "x[i]" in the NIntegrate is playing the role of "z" in the function definition.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.