Please check my math formula

Greetings,

I am beginning to replicate formulas that were formally in my .ino sketches into MIT App Inventor. Would someone please look over the following two formulas and tell me where I am deviating from common logic? In the .ino sketch, getTemp is the temperature in Celsius and Humid is the relative humidity percentage. In the .ala file, Temperature_C_Label.Text is the temperature in Celsius and Humidity_Label.Text is the relative humidity percentage.

The .ino sketch returns what is close to a wet-bulb temperature but the .ala is miles off. I have assembled it bit-by-bit and disassembled it looking for the problem but I am at a loss.

Basically, I am screwing up the .ala expression due to a lack of understanding about the nature of block assembly in the Visual landscape. Would someone please edit my .ala to replicate the .ino so I can study the differences from my "logic," or at least point out any glaring errors? Thank you so much!

.ino Formula:
Twet = getTemp * atan(0.151977 * sqrt(Humid + 8.313659)) + atan(getTemp + Humid) - atan(Humid - 1.676331) + 0.00391838 * pow( Humid, 1.5) * atan(0.023101 * Humid) - 4.686035;

.png of my block code:

.ala of my block code:
Formula_Question.aia (2.2 KB)

You have not clearly indicated precedence by using rounded brackets, but just by following your written formula, I get this:

image

You had an extra -0.4686035 in your block formula...

(note: you can right click on a maths block to change the input from external to internal)

The procedure block is draggable, click on it then you can drag it into your blocks editor.

Thank you so much for that. I had no idea I could stack the formula instead of making it a mile long! Your way makes it so much easier to see the interaction of the core components.

There is a further consideration.

AI2's trig functions are in degrees, not radians like in Excel.

From

I see

2. Empirical expression for wet-bulb temperature

Presented here is an empirical inverse solution found by a function fit to the data in Fig. 1. It yields Tw (°C) as a function of T (°C) and RH% (where a humidity such as 65.8% is input as the number 65.8):

e1View Expanded

The arctangent function uses argument values as if they are in radians. The curves in Fig. 2 were calculated using Eq. (1) to show Tw as an explicit function of T and RH%. Equation (1) is valid for a pressure of 101.325 kPa and for the combinations of dry-bulb temperatures and relative humidities as plotted in Fig. 2. Saturation is with respect to liquid water over all temperatures.

I leave it to you to double check this.

1 Like

Hi, again. How do I make my math blocks vertical and not horizontal? I cannot find a switch or anything that lets me stack two multiples above each other instead of side-by-side Thank you for the assistance.

Sorry, I missed the right-click part because I didn't understand the difference between internal and external sockets (duh;). Thanks, again!

All is now well!

I had to convert degrees to radians to make the formula work.

Thanks, again!

That doesn't look right, from the perspective of units analysis.

atan takes a tangent (a ratio) as input and outputs an angle in degrees.

If you want that angle to be in radians, you have to do that on the output (left) side of the atan conversion, not the input (right) side.

1 Like

Greetings, Master (User)

That was the answer. I really had tried using the degrees to radians blocks in both locations, but I somehow missed the correct output. Thank you so much for your great guidance and mentoring.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.