#Cross method calculation

1 messages · Page 1 of 1 (latest)

stone oasis
#

Hey everyone, I hope you don't mind me making a thread, however, due to the nature and complexity of the problem I'm convinced this is the best option. So, what is the problem? - you may ask. As the title of this thread suggests, it is regarding a cross method calculation. For those who aren't aware of what it is, take the following as a example:

36 g of water - 46 g of sodium
x g of water - 1 g of sodium

x = 36 * 1 / 46 = about 0,78 g```

And no, I did not choose the use of cross method calculation in chemistry as an example without a purpose. I am working on a chemical reaction simulator in Unity and yeah. So, you might be asking, what's the problem? And the problem is this code:
#

Because the Atomic Mass is an array, when i is greater than the lenght of the array - 1, it will simply throw an error. And since we're talking about cross method calculation, I need to add i + 1.

#

I got an idea just now, let's see

stone oasis
#

Nope

hidden quarry
#

could use a list instead - it works very much like an array, but is much easier to resize.

#

(automatic)

hidden quarry
#

🤷‍♂️ maybe I misunderstood the question

stone oasis
#

Hey everyone,
I'm having an issue. I believe that all, or at least most of you, know what a cross method equation is. If not, here's an example:

36 g of water - 46 g of sodium
x g of water - 1 g of sodium

x = 36 * 1 / 46 = about 0,78 g```

Coding this in C# is *especially* challenging. And no, I didn't choose chemical application of this method as an example without a reason, as I'm working on a chemical reaction simulator in unity. Moving on, one of the things you have to do is to compare which of the *two* (or more) x, y, z etc. (the output) is the greatest, aka, x > y > z and so on, and only conduct further calculations on that one specific result. It's very challenging because the data is stored in arrays, with the database looking like this:
```json
{
  "Na + H2O": {
    "Output": ["NaOH", "H2"],
    "Balanced": "2Na + 2H2O → 2NaOH + H2",
    "Exothermic": true,
    "State": [ "liquid", "gas" ],
    "MeltingPoint": 318,
    "BoilingPoint": 1388,
    "Solubility": 109,
    "SpecificHeat": 3.24,
    "AtomicMass": [ 46, 36 ],
    "MolecularMass": [ 80, 2 ],
    "Stechiometry": [36, 46]
  }
}```

For the sake of simplicity, we will focus on the values that really matter: "AtomicMass", "MolecularMass", "Stechiometry" (And yes, I know that they all are essentially all and the same, perhaps after I got an answer I will manage to make to fit this all into a single value).
In order to calculate the `x`, I'm using the following code:
```cs
Check = compoundInfo[equationFormat].Stechiometry[i] * ReactantAmount[fetchNameReactant] / compoundInfo[equationFormat].AtomicMass[i];```
As I said, the difficulty here is that you've gotta calculate all of the values and then compare them. And note that there *probably* won't be a constant amount of elements in an array depending on a kind of compound, so yeah. Any help would be appreciated.