My Math Forum Simplifying an equation

 Elementary Math Fractions, Percentages, Word Problems, Equations, Inequations, Factorization, Expansion

January 29th, 2018, 03:49 AM   #1
Member

Joined: Jan 2016
From: Uk

Posts: 74
Thanks: 2

Simplifying an equation

Hi,
I am not much of a mathematician or computer programmer, but I'm trying to include an equation into a program.

Here is the equation:

What happens is the program READs 12x Temperature/Pressure addresses, to give T1-T3 and P1-P9 (Shown in the equation as dig_X)

I want to READ these values first then add them into the program while simplifying it.

Any help would be much appreciated.
cheers, Camerart.
Attached Files
 CALC.txt (4.4 KB, 7 views)

January 29th, 2018, 04:11 AM   #2
Senior Member

Joined: Feb 2016
From: Australia

Posts: 1,506
Thanks: 502

Math Focus: Yet to find out.
Quote:
 Originally Posted by camerart Hi, I am not much of a mathematician or computer programmer, but I'm trying to include an equation into a program. Here is the equation: What happens is the program READs 12x Temperature/Pressure addresses, to give T1-T3 and P1-P9 (Shown in the equation as dig_X) I want to READ these values first then add them into the program while simplifying it. Any help would be much appreciated. cheers, Camerart.
The code in the text file is quite hard to read. Can you highlight which line(s) you are referring to?

 January 29th, 2018, 04:31 AM #3 Senior Member   Joined: Apr 2014 From: Glasgow Posts: 2,086 Thanks: 700 Math Focus: Physics, mathematical modelling, numerical and computational solutions It looks like a C program. I would copy and paste the code into a new file and the wrap those two different pieces of functionality into two separate methods. For example, you could do something like: Code: double GetTemperatureAsDouble() { } char* GetTemperatureAsString() { } I'm not very good at C or C++, but I don't think you'd have to change much except to make sure the types for the methods and the return variables in the code match and make sure that there's declarations in the methods for all of the relevant variables. Once you've got the methods available for use, you can put them in a program like this: Code: int main { double mytemp; char* tempString; myTemp = GetTemperatureAsDouble(); tempString = GetTemperatureAsString(); return 0; } If the program is more sophisticated you might need to make a .dll and then call the functions using an interface declaration. I have no idea how to do that though. Thanks from Joppy
 January 29th, 2018, 04:36 AM #4 Member   Joined: Jan 2016 From: Uk Posts: 74 Thanks: 2 Hi J, It is hard to read, and I'm trying to reduce it so it is simpler. NOTE: DOUBLE is a double precision floating point number ~ 16 digits precision. Take this line: var1 = (((double) adc_t) / 16384.0 –((double) dig_t1) / 1024.0) * ((double) dig_t2) ; I have READ and calculated all of the 'dig_xx' elements from the module, so I think it could be shortened to something like this: var1 = (((double) adc_t) / 16384.0 –((27100) / 1024.0) * ((double) 25631) var1 = (((adc_t) / 16384.0 –(26.46484375 * ( 25631) var1 = (((adc_t) / 16384.0 –678,320.41015625 I'm sure there are a few mistakes already, and I have no confidence to try. Are you able to read Python, as I have a similar equation? c.
January 29th, 2018, 05:40 AM   #5
Member

Joined: Jan 2016
From: Uk

Posts: 74
Thanks: 2

Quote:
 Originally Posted by Benit13 It looks like a C program. I would copy and paste the code into a new file and the wrap those two different pieces of functionality into two separate methods. For example, you could do something like: Code: double GetTemperatureAsDouble() { } char* GetTemperatureAsString() { } I'm not very good at C or C++, but I don't think you'd have to change much except to make sure the types for the methods and the return variables in the code match and make sure that there's declarations in the methods for all of the relevant variables. Once you've got the methods available for use, you can put them in a program like this: Code: int main { double mytemp; char* tempString; myTemp = GetTemperatureAsDouble(); tempString = GetTemperatureAsString(); return 0; } If the program is more sophisticated you might need to make a .dll and then call the functions using an interface declaration. I have no idea how to do that though.
Hi B,
I am not using C, but Oshonsoft BASIC, which has all sorts of gotchas.
This is not really a computing question, but a mathematical one. I am trying to 'simplify down' the equation mathematically, them write it and test it as i go along.
C.

January 29th, 2018, 06:03 AM   #6
Senior Member

Joined: Apr 2014
From: Glasgow

Posts: 2,086
Thanks: 700

Math Focus: Physics, mathematical modelling, numerical and computational solutions
Okay, I understand. No wonder you're having trouble then... the quality of code is awful (very 1980s!) and the comments refer to the pages of a book or article, so do you have the book/article it is referring to?

Quote:
 Originally Posted by camerart Hi J, It is hard to read, and I'm trying to reduce it so it is simpler. NOTE: DOUBLE is a double precision floating point number ~ 16 digits precision. Take this line: var1 = (((double) adc_t) / 16384.0 –((double) dig_t1) / 1024.0) * ((double) dig_t2) ; I have READ and calculated all of the 'dig_xx' elements from the module, so I think it could be shortened to something like this: var1 = (((double) adc_t) / 16384.0 –((27100) / 1024.0) * ((double) 25631) var1 = (((adc_t) / 16384.0 –(26.46484375 * ( 25631) var1 = (((adc_t) / 16384.0 –678,320.41015625 I'm sure there are a few mistakes already, and I have no confidence to try. Are you able to read Python, as I have a similar equation? c.
I am very familiar with python, so feel free to post stuff using that.

I don't know anything about ADCs, but, after a quick Google search (see for example Calculate temperature from ADC value of MCP9701A sensor | Microchip), it seems as if the equation is a conversion that relates an ADC voltage value (as outputted from an ADC connected to a temperature sensor) to the temperature being sensed. The equation is probably something like

$\displaystyle T = A (V - B)$

where T is temperature (in Celsius), V is ADC voltage (in Volts) and A and B are coefficients that dictate the calibration of the sensor and ADC component. A is a "temperature coefficient" and B is an "offset" .

If you have

$\displaystyle T = V / 16384.0 – 678320$

Then you have

$\displaystyle A = \frac{1}{16384} = 0.000061$

and

$\displaystyle B = 678320 * 16384 = 1.11 \times 10^{10}$

Those values don't seem like sensible values for a calibration scheme though for an ADC...

January 29th, 2018, 06:25 AM   #7
Member

Joined: Jan 2016
From: Uk

Posts: 74
Thanks: 2

Quote:
 Originally Posted by Benit13 Okay, I understand. No wonder you're having trouble then... the quality of code is awful (very 1980s!) and the comments refer to the pages of a book or article, so do you have the book/article it is referring to? I am very familiar with python, so feel free to post stuff using that. I don't know anything about ADCs, but, after a quick Google search (see for example Calculate temperature from ADC value of MCP9701A sensor | Microchip), it seems as if the equation is a conversion that relates an ADC voltage value (as outputted from an ADC connected to a temperature sensor) to the temperature being sensed. The equation is probably something like $\displaystyle T = A (V - B)$ where T is temperature (in Celsius), V is ADC voltage (in Volts) and A and B are coefficients that dictate the calibration of the sensor and ADC component. A is a "temperature coefficient" and B is an "offset" . If you have $\displaystyle T = V / 16384.0 – 678320$ Then you have $\displaystyle A = \frac{1}{16384} = 0.000061$ and $\displaystyle B = 678320 * 16384 = 1.11 \times 10^{10}$ Those values don't seem like sensible values for a calibration scheme though for an ADC...
Hi B,
Here's a similar Python program:

The addresses may be different, I haven't check them fully, till you like the look of it.

Notes are marked ################
All between @@@@@@@@@@@@@@ has been READ and calculated seprately, so fixed.

C.
Attached Files
 BMP280 CALC.txt (6.2 KB, 0 views)

 Tags equation, simplifying

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post chopnhack Algebra 3 February 22nd, 2017 08:28 PM bobred Algebra 2 February 2nd, 2015 08:35 AM Kinh Algebra 5 March 14th, 2014 12:00 AM bytelogik Algebra 3 June 17th, 2012 07:01 PM jakeward123 Algebra 4 May 11th, 2012 01:37 PM

 Contact - Home - Forums - Cryptocurrency Forum - Top