Unable to integrate user-defined function

85 Views Asked by At

I defined a function to return the actual roots of a quartic function. theCentralTrace[t] is an NDSolve solution of the trace over the function of a particular branch. But this is only approximate. I wish to obtain high-precision values of the function over the trace by solving for the roots with NSolve and then selecting the root that matches the (approximate) value of the trace. The function getDigits returns floating point numbers as a sequence of 5 digits so that Position can find the root that matches the value of the trace. I can plot this function via:

Plot[myFunction[t],{t,tStart,tEnd}]

but if I attempt to integrate it via:

NIntegrate[myFunction[t],{t,tStart,tEnd}]

I receive errors: The conditional in the code return an unevaluated 't' so Position fails. I was wondering if someone could help me fix this. Thanks.

  myFunction[t_] := Module[{cDigits, fVal, 
    fDigits, pos, cVal},
  cVal = theCentralTrace[t];
  cDigits = getDigits[cVal, 5];
  fVal = w /. NSolve[theFunction == 0 /. z - 
      > rnorm Exp[I t], w];
  fDigits = getDigits[fVal, 5];
  pos = Position[fDigits, cDigits[[1]]];
  If[Length[pos] == 0,
     Print[t];
     Abort[];
  ];
  Re[fVal[[pos[[1, 1]]]]]
  ];