0

I wrote a program that defines two piecewise functions "gradino[x_]" and "gradino1[x_]", where x is a vector of m components.

I'm not able to write these functions explicitly using the x_i, I need to keep x as a vector.

I need to measure the distance between these two function doing:

Integrate[Abs[gradino[x]-gradino1[x]],{x[[1]],0,100},{x[[2],0,100},{x[[3]],0,100}...{x[[m]],0,100}]

but it's not working.

Any idea how to do this? Remembering that I can't simply express gradino[x1_,x2_ etc...].

2 Answers2

0

re: "its not working" posting the actual error message is usually a good idea, in this case "Part specification x[[1]] is longer than depth of object.".. tells you exactly what the problem is. If x is not already defined as a list you cannot use list elements as integration variables.

f[y_] := y[[1]]  y[[2]];
Integrate[ f[x] , {x[[1]], 0, 1}, {x[[2]], 0, 1}]

(* error  Part specification x[[1]] is longer than depth of object. *)

If you first define x as a list, then it works:

x = Array[z, 2];
Integrate[ f[x] , {x[[1]], 0, 1}, {x[[2]], 0, 1}]

(*1/4*)

Note you can not do this with nintegrate:

NIntegrate[ f[x] , {x[[1]], 0, 1}, {x[[2]], 0, 1}]

(*error  Tag Part in x[[1]] is Protected *)

you need to use the explicit elements:

NIntegrate[ f[x] , {z[1], 0, 1}, {z[2], 0, 1}]
(* 0.25 *)
agentp
  • 6,849
  • 2
  • 19
  • 37
0

According to the model above, with

x = Array[z, 2];

why the following is ok:

f[y_] := NIntegrate[y[[1]] y[[2]] t, {t, 0, 1}];
NIntegrate[f[x], {z[1], 0, 1}, {z[2], 0, 1}]

but the following is not:

f[y_] := NIntegrate[y[[1]] y[[2]] Exp[t], {t, 0, 1}];
NIntegrate[f[x], {z[1], 0, 1}, {z[2], 0, 1}]

The only difference is changing t in the inner integration into Exp[t].

Jens Bergvall
  • 1,617
  • 2
  • 24
  • 54
Juha M
  • 1