Disordered Operations

Happy Midweek, Everyone

It is my desire that one of you less dyslexic, mathematically-inclined individuals (that would be just about everyone else here;) look over my formula (presented below) and suggest where I might have blown my understanding of the Order of Operations (you know, PEDMAS, et al). I am not requesting a rewrite, just some red circles where my logic has failed me.

This is a formula for calculating enthalpy from the temperature in Fahrenheit, and the relative humidity. The text formula from my Arduino IDE works just fine in its own environment. My block interpretation must be missing something, as the results differ.

Any hints or outright directives would be greatly appreciated.

Here is the unmarked text of the formula:

float enthalpy = 0.24Ftemp+(0.6219)(0.01*(0.000000007401234pow(Ftemp,4) - 0.000000493526794pow(Ftemp,3) + 0.000071281097208pow(Ftemp,2) -
0.000489806163078
Ftemp + 0.039762055806989)Humid)/(14.7-(0.01(0.000000007401234pow(Ftemp,4) - 0.000000493526794pow(Ftemp,3) +
0.000071281097208pow(Ftemp,2) - 0.000489806163078Ftemp + 0.039762055806989)Humid))(1061.2+0.444*Ftemp);

Enthalpy_Formula.pdf (21.9 KB)

Can you please save that block as an image and post it here, so I can drag it into a project, I see a couple of problems

Do you have values for the variables (textboxes) ? Do you know what the answer should be - say from another source ?

1 Like

Never mind...

Try this (blocks are draggable):

blocks (14)

2 Likes

Greetings,

I had a busy day out yesterday and was unfit to respond last night. Thank you very much for this design recommendation, I will test it later this morning and report back. My response would have been that I have had favorable results from the Arduino code that satisfied several online enthalpy calculators and that the code was copied from the following link - Source of Enthalpy Formula

Thanks, again,)

Good Afternoon,

I have played with this design for awhile. The small block dragged into the App Inventor but the large one wouldn't transfer. I clicked and dragged but, upon release, it disappeared. Most likely user error on my part.

When you have a moment, would you please aid me in translating your design into my application? You call the function through a plug-in that I am not sure where to place. I called the function from a checkbox click and I do not see quite how to incorporate the two.

I am including the operative blocks as an image. Thanks for your assistance and patience.

For the draggable block, click on it until it is the biggest it can be (should be two clicks)

Then you can drag it.

Hi Baran

Is this the enthalpy formula you are using?

Screenshot 2024-08-22 at 19-02-36 ChatGPT

Where:

  • h = Enthalpy

  • cp = Specific heat capacity of the air

  • T = Temperature in degrees Celsius

  • p = Atmospheric pressure

  • h_{fg} = Latent heat of vaporization

  • R = Gas constant

  • RH = Relative Humidity in percentage

    • Because I honestly didn't understand much of your code. But I know you are only receiving the humidity and temperature data, or am I wrong?

A long time ago, when I was at university, did some projects with Arduaros (Chinese Arduinos :rofl:). And i use that formula to calculate the enthalpy (several times).

Well i did a extension for you, but Niotron is getting problems with compiling.
Maybe @TIMAI2 can lend a hand.

Source Code
package com.jd.Enthalpy;

import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;

@DesignerComponent(
        version = 1,
        description = "Humidity % and Temperatura C°",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "https://img.icons8.com/?size=100&id=C44VkfkDwlMV&format=png&color=000000")
/**
 * Extension to calculate enthalpy given temperature and humidity.
 */
@SimpleObject
public class EnthalpyCalculator extends AndroidNonvisibleComponent {

    // Default values
    private float cp = 1.006f;  // Specific heat capacity of air in kJ/kgK
    private float p = 101.325f; // Atmospheric pressure in kPa
    private float h_fg = 2500f; // Latent heat of vaporization in kJ/kg
    private float R = 0.462f;   // Gas constant in kJ/kgK

    // Constructor
    public EnthalpyCalculator(ComponentContainer container) {
        super(container.$form());
    }

    @SimpleProperty(description = "Set the Specific heat capacity of the air (cp) in kJ/kgK")
    public void setCp(float cp) {
        this.cp = cp;
    }

    @SimpleProperty(description = "Get the Specific heat capacity of the air (cp) kJ/kgK")
    public float getCp() {
        return this.cp;
    }

    @SimpleProperty(description = "Set the Atmospheric pressure (p) in kPa")
    public void setP(float p) {
        this.p = p;
    }

    @SimpleProperty(description = "Get the Atmospheric pressure (p) in kPa")
    public float getP() {
        return this.p;
    }

    @SimpleProperty(description = "Set the Latent heat of vaporization (h_fg) in kJ/kg")
    public void setHfg(float h_fg) {
        this.h_fg = h_fg;
    }

    @SimpleProperty(description = "Get the Latent heat of vaporization (h_fg) in kJ/kg")
    public float getHfg() {
        return this.h_fg;
    }

    @SimpleProperty(description = "Set the Gas constant (R) in kJ/kgK")
    public void setR(float R) {
        this.R = R;
    }

    @SimpleProperty(description = "Get the Gas constant (R) in kJ/kgK")
    public float getR() {
        return this.R;
    }

    @SimpleFunction(description = "Calculate the enthalpy given temperature and humidity")
    public float calculateEnthalpy(float temperature, float humidity) {
        // Calculate enthalpy using the formula
        float RH = humidity; // Assuming humidity is in percentage
        return (cp * temperature) + ((p * h_fg / R) * (RH / 100));
    }
}
Niotron IDE Log
Execution Log

Started Compiling Project EnthalpyCalculator
Buildfile: /compiler/androidX/build.xml

javac:
[mkdir] Created dir: /compiler/androidX/build/udtNl/classes
[javac] Compiling 1 source file to /compiler/androidX/build/udtNl/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/simple_components.json
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/simple_components.txt
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/simple_components_build_info.json
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/AutogeneratedOdeMessages.java
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/ComponentsTranslation.java

process:
[mkdir] Created dir: /compiler/androidX/out/udtNl
[mkdir] Created dir: /compiler/androidX/build/udtNl/externalComponents
[mkdir] Created dir: /compiler/androidX/build/udtNl/externalComponents-classes
[java]
[java] Extensions : Generating extensions

unjarAllExtensionLibraries:

jarAllExtensions:

dexAllExtensions:

extensions:

BUILD SUCCESSFUL
Total time: 0 seconds

P/D: I am practicing Java

FYI - images with more than one procedure or event block, or any kind of non-connected block are not draggable.

They have to be standalone image files.

1 Like

Good Morning,

No, the formula I use depends on only the temperature in Fahrenheit and the relative humidity. I was unaware of an enthalpy formula using the "Latent heat of evaporation" but I will run some numbers through it. The formula I use which has always worked for me is: Float enthalpy = 0.24*Ftemp+(0.6219)*(0.01*(0.000000007401234*pow(Ftemp,4) - 0.000000493526794*pow(Ftemp,3) + 0.000071281097208*pow(Ftemp,2) - 0.000489806163078*Ftemp + 0.039762055806989)*Humid)/(14.7-(0.01*(0.000000007401234*pow(Ftemp,4) - 0.000000493526794*pow(Ftemp,3) + 0.000071281097208*pow(Ftemp,2) - 0.000489806163078*Ftemp + 0.039762055806989)*Humid))*(1061.2+0.444*Ftemp);

Where Ftemp is the temperature in Fahrenheit and Humidity is the relative humidity percentage (0 - 100). I really think that TIMA12 had it right in this example - that I must "call" my variables in a "get" function but I am still having difficulty incorporating that logic into my "when checkbox clicked" block.

So, TIMA12 was kind enough to convert my enthalpy formula to a "call" and "get" function which, I understand from your previous communications is much more stable/accurate/dependable/etc. While I tried to map TIMA12's function onto my system of "when checkbox clicked," I find I am unable to plug his creation anywhere into my system (see my previous post).

I think I can actually get this myself if I understand the sequence of assembling a statement that uses the get variable command and I start from scratch. Would you please direct me to the basics that will ease my confusion or give me a simple "step 1, step 2, etc.) guide to creating variables that I can call in the appropriate blocks.. My greatest "duh-what" is how to get the orange variables to show up in the purple get blocks. Once I brought TIMA12's creation into my file, it "stood alone" and would not share variables with my blocks. Please understand that you may have shared this and I may have missed it in my overwhelm. Thanks again for any clarification.

See Chapter 21 from
http://www.appinventor.org/book2
from

Just follow my instructions above to drag the procedure into your blocks editor.

Alternatively, you can download the image, and then drag it in from your file manager.

That ultimately worked but I am a a loss as to how to interface my "when checkbox checked" block to your call for the enthalpy function. I am going to read over a link that ABG sent regarding procedures (for Dummy's) and see if I can recreate what you provided in my environment. I'm determined to get these 2 or 3 neurons up and running;).

image

Thank you for that example. I am starting to feel like I am catching on (still some conditionals;). I posted a response question to ABG regarding a small file he created, if you choose to comment on it. Thank you, again. I am grinding on.

He's baaaaaaack!

Hi, could you address a few questions that I cannot seem to find the answer to? I am still not sure why variables are so great in functions but text boxes are not recommended, even though the contents of the text box are moved into the variable to be read. Were you also( in your dew point example) simply showing how procedures can be used to avoid redundancy and defined for those unfamiliar with the code? Thank you for any clarity you may be able to add.

Greetings,

OK, I've played with that for a couple of days and I am still missing something that is preventing me from calling this enthalpy procedure in the same manor that I would call any other procedure. If you would be so kind, please look over the two PNGs below. The first is typical of most of my check box functions. The second is me trying to fit what you have shown me into my application. As you can see, I can't get there from here with the logic(?) I am using. If you could draw some lines and arrows indication what goes where, I would really appreciate the assist. I do not always find the correct procedure blocks in the bin leading me to believe that I have missed a step.

The second example works fine. It just doesn't completely fulfil the purpose of a procedure.
Keeping procedures/functions/methods as generalized or parametrized is good coding. This maximizes reusability.
The second example, in this case, voids the use of the RH variable (which, honestly, is useless; but including it makes the code much more readable).

Could you please right-click -> download the individual events and procedures?
Assuming what you want to do is similar to what you've done in the save_Dry_Air_Volume procedure:

Inside the save_Enthalpy procedure, call another "to result" procedure to the enthalpy formula (make sure you pass the FTemp and Humid arguments), and then set the value of the corresponding key to that.