Unable to integrate this user-defined function

In summary, "Unable to integrate this user-defined function" is a common error message that may occur when trying to use a user-defined function in a scientific software or program. This message indicates that the function cannot be integrated into the code or process for various reasons, such as syntax errors, conflicts with other functions or code, or incompatibility with the software or program. Fixing this issue may require troubleshooting and checking the function's syntax, compatibility, and conflicts with other code. Depending on the cause of the error, it may still be possible to use the user-defined function, but it may require some corrections or may not be possible at all. Various resources, such as online forums, official documentation, and experienced programmers, can provide assistance
  • #1
aheight
321
109
I am working with a polynomial and wish to integrate over one of it's branch surfaces with high precision. The function is:

## -z^2 + z^3 + w (-4 z + 3 z^2) + w^3 (-2 + 8 z + 4 z^2 - 4 z^3) + w^2 (-z^3 - 9 z^4) + w^4 (6 - 8 z^2 + 7 z^3 + 8 z^4)=0##

So I first solve the associated differential equation to obtain a trace over ##w(z)## . This is theCentralTrace[t]. Next, in order to obtain precise values of the function over this trace, I solve for the roots over the trace. Then I can compare the trace values to the list of roots and get a more precise value of the function over the trace. As written, I can plot myFunction[t]. However, when I attempt to integrate myFunction[t] via:

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

the conditional in the code returns an unevaluated 't' so the Position fails. The function getDigits in the code simply converts the floating point numbers to integer sequences so I can make an exact comparison to a particular precision (5 in the code). I was wondering if someone could help me with this.

Thanks.

Mathematica:
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]]]]]
  ];
 
Physics news on Phys.org
  • #2


Hello,

Thank you for sharing your code and explaining your problem. I am a scientist with experience in numerical integration and differential equations, and I would be happy to help you with this issue.

After reviewing your code, I believe the problem lies in your use of the Re[] function in the last line of the myFunction[t_]. The Re[] function takes the real part of a complex number, but in this case, you are using it on a list of complex numbers. This is causing the conditional in your code to return an unevaluated 't', as you mentioned.

To fix this issue, you can use the Part (or [[ ]]) function to extract the real part of the complex number at the desired position. So the last line of your code would become:

Re[fVal[[pos[[1, 1]]]][[1]]]

This will extract the real part of the complex number at the first position in the list of fVal, which is what I believe you are trying to achieve.

I hope this helps and please let me know if you have any further questions or if you need any more clarification. Good luck with your project!
 

1. What does it mean when I receive an error message saying "Unable to integrate this user-defined function"?

This error message typically occurs when trying to integrate a user-defined function (UDF) into a larger code or model. It means that the UDF is not compatible with the specific code or model that you are using.

2. How can I fix the "Unable to integrate this user-defined function" error?

The first step is to check the compatibility of the UDF with the code or model that you are using. If the UDF was created by someone else, you can contact them for assistance. If you created the UDF, you may need to modify it to make it compatible with the code or model.

3. Can I use any type of user-defined function in my code or model?

No, not all UDFs are compatible with all codes or models. It is important to carefully check the compatibility before attempting to integrate a UDF. It is also a good idea to test the UDF in a small-scale model or code before using it in a larger one.

4. Is there a specific format or structure that UDFs need to follow to be integrated successfully?

Yes, UDFs typically have specific requirements in terms of format and structure in order to be integrated successfully. These requirements may vary depending on the code or model you are using. It is important to carefully read the documentation or guidelines for the specific code or model to ensure that your UDF follows the correct format.

5. Are there any troubleshooting steps I can take if I encounter the "Unable to integrate this user-defined function" error?

Yes, there are a few steps you can take to troubleshoot this error. First, double check the compatibility of the UDF with your code or model. Then, try testing the UDF in a smaller model or code to see if it works. You can also reach out to the developer of the UDF or consult online forums for assistance. If all else fails, you may need to modify the UDF or look for an alternative solution.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
228
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
558
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Back
Top