# Errors in code for fission yield analysis across different patterns

**URL:** <https://community.wolfram.com/t/errors-in-code-for-fission-yield-analysis-across-different-patterns/24830>\
**Category:** Questions\
**Tags:** chemistry, optimization, tuning-and-debugging\
**Created:** [November 28, 2024, 2:32pm UTC](https://community.wolfram.com/t/errors-in-code-for-fission-yield-analysis-across-different-patterns/24830 "2024-11-28T14:32:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![etcconversion](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@etcconversion](https://community.wolfram.com/u/etcconversion)\
**Post date:** [November 28, 2024, 2:32pm UTC](https://community.wolfram.com/t/errors-in-code-for-fission-yield-analysis-across-different-patterns/24830/1 "2024-11-28T14:32:27Z")

</div>

I am working on a Mathematica program to analyze fission yield data of U-235. The program calculates results for 5 different patterns based on neutron incident energies. While the calculation works correctly for pattern = 3, it produces errors for other patterns such as pattern = 1.

Key errors include:

Union::normal: Nonatomic expression expected at position 1 in Union[vars12].  
Part::take: Cannot take positions 6 through 42 in datax2.  
FindMinimum::vloc: The variable Union[vars12] cannot be localized so that it can be assigned to numerical values.

The result Reff becomes undefined (Indeterminate) or infinite.  
What might be causing these issues, and how can I modify the code to ensure correct calculations for all patterns?

Note:

When running the program on Mathematica version 11.3 or later, changes in the `FindMinimum` function result in errors even for the previously working pattern. Therefore, I kindly request that this issue be evaluated on Mathematica version 11.2.

[U235Program2.nb](https://community.wolfram.com/uploads/short-url/3Xy4Y1FQxC6V8dLwqTElmF0Ragw.nb) (94 KB)

---

<div class="post-metadata">

**Author:** ![etcconversion](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@etcconversion](https://community.wolfram.com/u/etcconversion)\
**Post date:** [November 29, 2024, 8:47am UTC](https://community.wolfram.com/t/errors-in-code-for-fission-yield-analysis-across-different-patterns/24830/2 "2024-11-29T08:47:37Z")

</div>

Resolved

I have resolved this issue. The cause was in the loop index configuration.

The following code:  
For[gxIndex = 1, gxIndex \<= Length[gxValues], gxIndex++,

was replaced with:  
For[gxIndex = statnum, gxIndex \<= endnum, gxIndex++,

By properly setting `statnum` and `endnum`, the loop now correctly reflects the calculation range, and all patterns work as expected. I apologize for any confusion caused and hope this solution helps others facing a similar issue.
