math problem

johnlong

Senior Member
Hi All
is it possible with the picaxe to do the following eq
0.6108*exp(17.27*T/(T+237.3)) 1st part
x/100*1st part
result =2nd part - 1st part
have tried removing the dec point then reaplying them but dont
seem to be making any head way as the results from the first part are less than 1
Code:
symbol svp=6108 '0.6108*10000
symbol tempcor=1727'17.27*100
symbol temprw=2373 '237.3*10
symbol dry=b12
symbol pp=w10
symbol result=w11
'0.6108*exp(17.27*dry/(dry+237.3)) first part of result
'second eq  pp/100*first part
'3rd eq 2nd eq - 1st eq
pp=80
dry=24

	w0=dry*tempcor/100 'w0 to= 17.27*dry after /
	sertxd ("dry*17.27=",32,#w0,cr,lf)'calculated result=414.48
	w1=dry+temprw/1000 'dry+237.3 after /
	sertxd ("dry*237.3=",32,#w1,cr,lf)'calculated result=261.3
	w2=w0/w1
	sertxd ("17,27*dry/237.3*dry for exp=",32,#w2,cr,lf)'calculated result=1.586
	w3=svp*w2 'svp=0.6108*exp
	sertxd ("w3=",32,#w3,cr,lf)'calculated=0.968
	w3=w3/10000	
	sertxd ("first part of eq=",32,#w3,cr,lf)
	w4=w3*100 '100*first section of equ 2
	sertxd (#w4,cr,lf)
	pp=pp/w4
	sertxd ("snd part result=",32,#pp,cr,lf)
	result=pp-w3/100
	sertxd ("result",32,#result,cr,lf)
	dry=result-w3
	sertxd ("dry=",32,#dry,cr,lf)
or as usual am I over thinking it
regards
john
 

hippy

Technical Support
Staff member
Could possibly do it via a lookup table, by implementing a floating point library, or by using an external maths co-processor.

Calculating ex would seem to be the hard part.
 

oracacle

Senior Member
that's a tricky bit of maths, it may help if we know what its for and how accurate it has to be.
There are a few floating point libraries on the forum but as far as I know non of them deal with exponentials so you maybe be forced into using something like the micro mega floating point unit. There have a been few people here who have used it, I have used the 32 bit variant in a project so can offer help if needed.
 

AllyCat

Senior Member
Hi,

Looks like it might be a Relative Humidity calculation, so are you only expecting an integer result in the range 0 - 100 (%), and is T in the range ~0 to ~70 (degrees C) ? That might help a lot, but I believe even the "professionals" may just use a lookup table. The maths are not going to be very easy, but should be possible even with just an 08M2. ;)

The "exp" will definitely need a lookup table (or other external assistance) for a PICaxe. I have a "general purpose" lookup/interpolation subroutine in preparation, but I've no idea when it may make its way into the code snippetts section, so don't hold your breath.

The ** operator is often useful for multiplying a "fractional" number. Create the number multiplied by 65536 (or you can use 256 with an X2) and then use the ** (or */ with X2) to get back to "real" (integer) numbers again.

If you need to divide by a large number (e.g. 9+ bits), then I have posted several "double-word" code snippetts to do that.

Cheers, Alan.
 

johnlong

Senior Member
Hi All
its for calculating AW water activity for microbial control
water activity is the available water needed here's the crazy part
it does not need to be a whole moleicule
therefore if 1 represents water less than one is the AW
bacteria can live at values down to 0.92 and molds and fungl spores down to 0.75
at levels below 0.7 they can not access the molecule
as the osmatic pressure at the cell membrane is not great enough to allow the water to cross
AW is the relationship between temp, humidity and partial pressure
so the idea is to keep the enviroment less than there needs but still at levels
comfortable for humans to work at
a lookup table would be quite large in size as it would have to take into account a large
range of possible values
never heard of a maths co-processor will goggle that
thanks
regard
john
 
Last edited:

AllyCat

Senior Member
Hi,

a lookup table would be quite large in size as it would have to take into account a large
range of possible values
Your formula only contains one variable (T) and then a division. Is there something you haven't told us?

IMHO you do NOT want to use a CoProcessor. Probably easier to learn how to use one of the Floating Point libraries written for PICaxe (but I doubt if that is needed either).

Cheers, Alan.
 

rq3

Senior Member
Hi All
its for calculating AW water activity for microbial control
water activity is the available water needed here's the crazy part
it does not need to be a whole moleicule
therefore if 1 represents water less than one is the AW
bacteria can live at values down to 0.92 and molds and fungl spores down to 0.75
at levels below 0.7 they can not access the molecule
as the osmatic pressure at the cell membrane is not great enough to allow the water to cross
AW is the relationship between temp, humidity and partial pressure
so the idea is to keep the enviroment less than there needs but still at levels
comfortable for humans to work at
a lookup table would be quite large in size as it would have to take into account a large
range of possible values
never heard of a maths co-processor will goggle that
thanks
regard
john
You learn something new every day! I'd never heard of water activity, but your description sounded an awful lot like relative humidity, so I had to google it!
Turns out that RH = aw x 100. Relative humidity is defined as water activity times 100 (or aw= RH/100). There are lots of relative humidity sensors that are Picaxe compatable, delivering a result in %RH. Some are even I2C or SPI. Like this one:
http://www.silabs.com/products/sensors/humidity

This would make the maths trivial. I know I've commited the cardinal sin of not actually answering your question, but maybe re-thinking what the end result actually means might lead to different hardware, and a question that is very easy to answer. Just a thought, and thanks for teaching me about water activity!
 

johnlong

Senior Member
Hi
thank you rq3
I think your comments may on reflection be a wiser course of action
being a strickly base 10 sort of guy 12 if I count my thums twice
like I said in post# 1 am I as usual over thinking it again
the comment on osmosis needs to be vapour not water
regards j
 
Last edited:

oracacle

Senior Member
speaks to mentioning what's its for. There is always someone who has done something and found a lot easier ways of doing things.
 

AllyCat

Senior Member
Hi,

Latest version of my division subroutine is here, to which I hope to add compatible interpolated lookup table routines for Trig functions and Log/NTC Thermistors, etc. in due course.

I believe the Sensiron SHT31-D is one of the "benchmark" Humidity sensors now. Absolutely tiny, but assembled on a Breakout board for around £10 (or perhaps less if you're patient).

Cheers, Alan.
 

oracacle

Senior Member
its strange, you posted this "maths problem" just I started research for a future project which has quite a large maths problem. To the point where it maybe abandoned due to its complexity and accuracy required. A bit more research and some spread sheets will be the final decider.
 

hippy

Technical Support
Staff member
a lookup table would be quite large in size as it would have to take into account a large range of possible values
As AllyCat notes, there is only one variable 'T' and that seems to be a temperature with integer centigrade value. As the example you gave was for T=24 it seems it would be in the region of 'room temperature' which likely reduces the range of T quite considerably. Having a 24C range with a resolution of 0.1C, output to three decimal places, would seem easily doable on with a PICAXE.
 

johnlong

Senior Member
As AllyCat notes, there is only one variable 'T' and that seems to be a temperature with integer centigrade value. As the example you gave was for T=24 it seems it would be in the region of 'room temperature' which likely reduces the range of T quite considerably. Having a 24C range with a resolution of 0.1C, output to three decimal places, would seem easily doable on with a PICAXE.
Hi
As mentioned the calculation looks at the AW of the water it free/boundness and a rq3 has mentioned easy to calculate RH/100
this does not take into account the availibility of the vapour for cellular resperation just a maybe total
Which was determined by Anderson D.B (1936) Ecology 17 no2 277-282
as the constant e raised by es Actual Vapour pressure/ Saturated Vapour Pressure
AVP= vapour pressure*T(dewpoint celceus*vapour pressure mmHg)/T(dewpoint Kelvin)= (saturated dewpoint) sd
SVP= vapour pressure*T(temp Kelvin*vapour pressure mmHg)/T(temp Kelvin)
giving es
ea is the (AW)RH/100*es potental usable value for resperation
the diffrence in the vapour pressure is determined by
ea-es
the volume in the RH that is usable for celluar resperation
So in effect you can have a AW of 0.96 but only 0.8 of that is usable
its the second part that is of intrest as at levells of 0.6 and below celluar resperation stops and the cells membrain dessicates
and the bacteria/ molds dies
by obtaining this value at any given temprature the (kill rate) of the environment can be determined

regards john
 

hippy

Technical Support
Staff member
As mentioned the calculation looks at the AW of the water ...
I am afraid that's all beyond me, not my field of expertise.

Given 'these are the input values, these are the expected output values for those, and this is the calculation to use', I may be able to suggest ways it could be done, but that's the limit of what I can really help with.
 

johnlong

Senior Member
Hi All
Hippy I very much doubt its beyond you not accepting that.
But being chewing it over maybe a lookup table is the answer
BigBut
if I produce a table in excel such as
C/RH100 95 90 85 80
15 1 0.9 0.93 0.812 0.79
16 1 0.95 0.937 0.823 0.791
17 1 0.96 0.944 0.834 0.792
18 1 0.97 0.951 0.845 0.793
19 1 0.98 0.958 0.856 0.794
20 1 0.99 0.965 0.867 0.795
21 1 1 0.972 0.878 0.796
22 1 1.01 0.979 0.889 0.797
23 1 1.02 0.986 0.9 0.798
24 1 1.03 0.993 0.911 0.799
25 1 1.04 1 0.922 0.8
sorry has not copied over nicely
how would you read that in the picaxe
ie its T=25 RH=80 expect to see 0.8
not a command I have any experiance with
regards
j
 

hippy

Technical Support
Staff member
One way to replicate that in a PICAXE would be to scale the results by 1000 and then use LOOKUP to deal the fact that some are word values, greater than 255 ...

Code:
Symbol t      = b0
Symbol rh     = b1
Symbol result = w1

t  = 25
rh = 80
Gosub Calc
BinToAscii result, b15,b14,b13,b12,b11
SerTxd( "T=",#t, 9, "RH=",#rh, 9, "Result=",b14,".",b13,b12,b11, CR,LF )
End

Calc:
  result = rh Max 100 Min 80 / 5 : result = 20 - result
  Select Case t
    Case 15 : LookUp result, ( 1000, 0900, 0930, 0812, 0790 ), result
    Case 16 : LookUp result, ( 1000, 0950, 0937, 0823, 0791 ), result
    Case 17 : LookUp result, ( 1000, 0960, 0944, 0834, 0792 ), result
    Case 18 : LookUp result, ( 1000, 0970, 0951, 0845, 0793 ), result
    Case 19 : LookUp result, ( 1000, 0980, 0958, 0856, 0794 ), result
    Case 20 : LookUp result, ( 1000, 0990, 0965, 0867, 0795 ), result
    Case 21 : LookUp result, ( 1000, 1000, 0972, 0878, 0796 ), result
    Case 22 : LookUp result, ( 1000, 1010, 0979, 0889, 0797 ), result
    Case 23 : LookUp result, ( 1000, 1020, 0986, 0900, 0798 ), result
    Case 24 : LookUp result, ( 1000, 1030, 0993, 0911, 0799 ), result
    Case 25 : LookUp result, ( 1000, 1040, 1000, 0922, 0800 ), result
  End Select
  Return
For T=25, RH=80 the result is 0800 which represents 0.800

If one were happy with just two decimal places, a result of 080 representing 0.80 -

Code:
Symbol t      = b0
Symbol rh     = b1
Symbol result = b2

t  = 25
rh = 80
Gosub Calc
BinToAscii result, b13,b12,b11
SerTxd( "T=",#t, 9, "RH=",#rh, 9, "Result=",b13,".",b12,b11, CR,LF )
End

Calc:
  result = rh Max 100 Min 80 / 5 : result = 20 - result
  result = t  Max 25  Min 15 - 15 * 5 + result
  Read result, result
  Return

  Eeprom ( 100, 090, 093, 081, 079 )
  Eeprom ( 100, 095, 093, 082, 079 )
  Eeprom ( 100, 096, 094, 083, 079 )
  Eeprom ( 100, 097, 095, 084, 079 )
  Eeprom ( 100, 098, 095, 085, 079 )
  Eeprom ( 100, 099, 096, 086, 079 )
  Eeprom ( 100, 100, 097, 087, 079 )
  Eeprom ( 100, 101, 097, 088, 079 )
  Eeprom ( 100, 102, 098, 090, 079 )
  Eeprom ( 100, 103, 099, 091, 079 )
  Eeprom ( 100, 104, 100, 092, 080 )
A word value EEPROM table could also be created.
 

johnlong

Senior Member
Wow
very nice
if I use the eeprom aproach do I first download the table to the picaxe
then download the program
the final table will be larger RH 100 - 20 and temp 40 - 5, 17 steps
I take it that I change Max 100 Min 20 / 17: result = 17?-result
for t max 40 Min 5 -5*17+result
regards and thank you
john
 
Last edited:

hippy

Technical Support
Staff member
I would download the table with the program.

For 17 RH values, 36 T values, that's 612 entries, so would require EEPROM and TABLE. You can calculate a virtual index, make 'result' a word variable ...

Code:
result = rh Max 100 Min 20 / 5 : result = 20 - result
result = t * 18 + result
If result > 512 Then
  result = result - 512
  Read result, result
Else
  ReadTable result, result
End If
Return

Table  ( .... )
:
Table  ( .... )
Eeprom ( .... )
:
It would a smaller table if you can create a table for T values, then calculate what the various RH values would be from that, or vice-versa.
 

johnlong

Senior Member
Thanks Hippy
thats a good idea about splitting the work load
I will look into that furthur funny you came up with t*18
was playing with your code using that today
it got it reading down 12 places nicely
If do take it though if I use the EEprom route I will
realy need to understand the block byte write ect
thourgth about table today until I reread the manual and found out its 255 btes big
too small for that amount of data
If I look at it more realisticaly and pull down the upper RH will
reduce the amount data needed and split it
thats a new term I have not heared before virtual index
thank you for the work
regards
john
 

johnlong

Senior Member
Hi Hippy
Thank you for the work
Virtual index is some thing I have never heard before
will look into it
A good idea about spliting the work load makes sense
as I discovered today thinking about a table that the 40x2
is 255 big like you say a large amount of data
regards
john
 

hippy

Technical Support
Staff member
Ah yes; X2's only have 256 bytes of Table. 14M2, 18M2 and 20M2 have 512 bytes.

The 40X2 has more slots so a LOOKUP scheme might work.
 

johnlong

Senior Member
Hi
Looked at the problem from a diffrent angle as has being commented the equasion
would be difficult for the more experianced here to get working
totally impossible for me
But it came to me temp and rh are in relationship to each other at any point therefore the pressure
along that gradient would therefore be constant
so I calculated the lines of pressure using graph paper to determine y=mx+b
M the raise and B the intersection of the y axis
this gave the 2 constants for the determination of the pressure
by placing temprature into the eq gives the desired RH for any temp
this is then compared against the actual RH to determine the actual pressure against desired

Code:
symbol Rhum=w3: symbol Hmsb=b6: symbol Hlsb=b7'evp boundries
symbol Dry=w4 'sensor reading temprature
symbol vH=b4 'upper constraint
symbol Vhl=b5 'lower constraint
symbol vT=b3  'set point
symbol mean=w5:symbol mmean=b14:symbol bmean=b15'M and B values for gradient and intersect
symbol rh=b2 'sensor value for humidity
symbol marker=b0
symbol pointer=b1
symbol EVP=b12'evapourist potental of the air
symbol mfive=10 ' m values raised by 10 used in the straight line determination y=mx+b to whole numbers
symbol bfive=56
symbol msix=11
symbol bsix=51
symbol mseven=14
symbol bseven=39
symbol meight=15
symbol beight=33
symbol mnine=18
symbol bnine=23
symbol mten=20
symbol bten=15
symbol meleven=19
symbol beleven=16
symbol mtwelve=21
symbol btwelve=5'4
symbol mavg=17
symbol bavg=28

	hsersetup   B9600_8, %001
	pinsD=%11110000
	vt=20
	rh =50
	dry=15
	vh=5
	vhl=12
	
	main:
	do  
			select case vH'Dry zone hum  
		case 5 hmsb=mfive*vt/10+bfive'factor back in the decimal value /10 
		case 6 hmsb=msix*vt/10+bsix
		case 7 hmsb=mseven*vt/10+bseven
		
		end select  
		
		select case vHl 'Wet zone dehum temp inc
		
		case 10 hlsb=mten*vt/10+bten
		case 11 hlsb=meleven*vt/10+beleven
		case 12 hlsb=mtwelve*vt/10+btwelve
		end select 	
		if vhl<12 and vh=5  then  'Mean of the presure line between 0.5 to 1.2KPa 
			mmean=meight:bmean=beight
		elseif vh>5 and vhl=12 then
			mmean=mnine:bmean=bnine	
		else
			mmean=mavg:bmean=bavg	
		endif 
			if hserflag <>0 then : if hserptr < 2 then: pause 10 : endif : get 0,pointer:get 1,marker:gosub alter:gosub HP:goto main:endif 		
				
		mean=mmean*dry/10+bmean 'calculation set to 0.8 to 0.9KPa boundries dependent on selection
		
		sertxd ("set temp=",32,#vt,32,"dry=",32,#dry,32,cr,lf)		
		sertxd ("Hmsb=",32,#hmsb,32,"Mean",32,#mean,32,"Lmsb=",32,#hlsb,32,32,cr,lf)
		
			gosub V_cal
			
		if pinD.7=1 then 'for simulation testing
			dry=dry+1
			rh=rh+2
			elseif pinD.6=1 then
				dry=dry-1
				rh=rh-2				
					endif 	
		pause 1000
	loop 

alter:
		select case pointer 'narrow the action range of the pressure lines
			case "a" if marker="+" then
				vh=vh+1 max 7
			elseif marker="-"then
				vh=vh-1 min 5
			endif 
		case "b" if marker="+" then
			vhl=vhl+1 max 12
			elseif marker="-" then
				vhl=vhl-1 min 10
				endif
	end select 
	return
V_Cal:

		b23=meight*dry/10+beight
		b24=mavg*dry/10+bavg
		b25=mnine*dry/10+bnine
		select case mean 'decimel as whole nummbers
		case =b23 evp=80
		case =b24 evp=85
		case =b25 evp=90
		end select 
		select case rh 'determines the diffrence in rh between mean and actual rh diffrence <---Mean--->
		case=mean b30=0
		
		case<mean b33=mean-rh 'evp values greater than mean 0.85/0.9--->	
		b33=b33*17/10 'pressure/%rh
		evp=evp+b33-4 'correction factor for mean
		
		case>mean b30=rh-mean 'evp values less than mean <----0.8/0.85		
			b30=b30*17/10 
			evp=evp-b30-4
		end select
		sertxd ("RH=",32,#rh,32,"B33=",32,#b33,32,"B30=",32,#b30,32,cr,lf)		
			
			sertxd ("EVP=",32,#evp,32,cr,lf)
			
			return

HP:
		hserflag=0
		hserptr=0
		pointer=0
		marker=0
		
		return
this way no lookup tables are needed and the eq are simplified
regards john
 
Last edited:

elektriker

New Member
hello John
your equation is:
0.6108 * exp (17.27 * T / (T + 237.3)) (= 1.part)
x / 100 * 1st part (= 2nd part)
Result = 2nd part - 1st part

My questions:
1. what is x in the 2nd part?
2. T in the first part in ° C?
T in which temperature range: e.g. 0-100 ° C or 15-25 ° C?
How many decimal places for T and for the result?

Perhaps they also have a completely calculated result with real numbers.
Since I do not speak English so well, I prefer a complete calculation with numbers.

Translated with google translator.

Thank you

with kind regards
Werner
 
Top