I am trying to make a function that works as follows: Integrate 1 for all t in the interval $ [0,1] $ such that the first element of function vstar
is positive. vstar
is a function that outputs a pair of real numbers. Unfortunately the test vstar[t, a1, a2, f1, f2, σ]][[1]] > 0
does not work as expected (this is waht I've tried):
D1[f1_, a1_, f2_, a2_,σ_] :=
NIntegrate [If[vstar[t, a1, a2, f1, f2,σ][[1]] > 0, 1, 0] f[t], {t, 0,
tup}, AccuracyGoal -> 8];
The way it is, Mathematica tests if the first slot of vstar
is greater than zero (that is $ t>0 $) rather than testing if the first part of the output of vstar
is greater than zero. vstar
is defined so that it evaluates only for numerical values. I think I need to evaluate the function vstar
before the test is performed, I just don't know how to do it - could someone explain how?
p.s. For further reference, here's the code of vstar
:
vstar[tt_?NumericQ, aa1_?NumericQ, aa2_?NumericQ,
ff1_?NumericQ, ff2_?NumericQ, σσ_?NumericQ] :=
Module[{list},
list = {objm, objs1, objs2} /. {t -> tt,
a1 -> aa1, a2 -> aa2, f1 -> ff1,
f2 -> ff2, σ -> σσ};
If[list[[1]] < 0 && list[[2]] < 0 && list[[3]] < 0, {0, 0},
Which[Ordering[list , -1] == {1}, {v1, v2} /. vm,
Ordering[list , -1] == {2}, {v1 /. v1s, 0},
Ordering[list, -1] == {3}, {0,
v2 /. v2s}] /. {t ->tt, a1 -> aa1,
a2 -> aa2, f1 -> ff1, f2 -> ff2, σ -> σσ}]]
If
clause so I suggest you edit the code to amend this (I have not touched your code other than formatting) and also provide the functionvstar
. May I also suggest you read the relevant section on formatting for future posts. $\endgroup$vstar
always gives out a pair{a,b}
where, say,0<a,b<1
, it will be easier to writevstar[args__]:=RandomReal[{0,1},{2,1}]
. Also, the page about formatting that I linked tells you that a code block is formatted easily by selecting the code a pressing ctrl + K. I have done that now, but you should be able to do it yourself in the future $\endgroup$