My Math Forum  

Go Back   My Math Forum > High School Math Forum > Elementary Math

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


Thanks Tree1Thanks
  • 1 Post By Benit13
Reply
 
LinkBack Thread Tools Display Modes
January 29th, 2018, 02:49 AM   #1
Member
 
Joined: Jan 2016
From: Uk

Posts: 80
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
File Type: txt CALC.txt (4.4 KB, 7 views)
camerart is offline  
 
January 29th, 2018, 03:11 AM   #2
Senior Member
 
Joined: Feb 2016
From: Australia

Posts: 1,610
Thanks: 550

Math Focus: Yet to find out.
Quote:
Originally Posted by camerart View Post
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?
Joppy is offline  
January 29th, 2018, 03:31 AM   #3
Senior Member
 
Joined: Apr 2014
From: Glasgow

Posts: 2,125
Thanks: 714

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()
{
    <code here for the Page 45 method>
}

char* GetTemperatureAsString()
{
    <code here for the page 46 method>
}
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
Benit13 is offline  
January 29th, 2018, 03:36 AM   #4
Member
 
Joined: Jan 2016
From: Uk

Posts: 80
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.
camerart is offline  
January 29th, 2018, 04:40 AM   #5
Member
 
Joined: Jan 2016
From: Uk

Posts: 80
Thanks: 2

Quote:
Originally Posted by Benit13 View Post
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()
{
    <code here for the Page 45 method>
}

char* GetTemperatureAsString()
{
    <code here for the page 46 method>
}
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.
camerart is offline  
January 29th, 2018, 05:03 AM   #6
Senior Member
 
Joined: Apr 2014
From: Glasgow

Posts: 2,125
Thanks: 714

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 View Post
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...
Benit13 is offline  
January 29th, 2018, 05:25 AM   #7
Member
 
Joined: Jan 2016
From: Uk

Posts: 80
Thanks: 2

Quote:
Originally Posted by Benit13 View Post
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
File Type: txt BMP280 CALC.txt (6.2 KB, 0 views)
camerart is offline  
Reply

  My Math Forum > High School Math Forum > Elementary Math

Tags
equation, simplifying



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assistance with simplifying an equation chopnhack Algebra 3 February 22nd, 2017 07:28 PM
Simplifying an equation bobred Algebra 2 February 2nd, 2015 07:35 AM
Simplifying this equation Kinh Algebra 5 March 13th, 2014 11:00 PM
Simplifying equation bytelogik Algebra 3 June 17th, 2012 06:01 PM
Simplifying an equation jakeward123 Algebra 4 May 11th, 2012 12:37 PM





Copyright © 2018 My Math Forum. All rights reserved.