I've written a program to quickly find the order of reactants for a given element in an integrated rate law for use in my AP Chemistry class. However, I'm running into one slight problem. The way you pick the order of reactants is by graphing three graphs: [A] versus t, ln[A] versus t, and 1/[A] versus t where [A] is concentration and t is time. You then pick the graph that produces the straightest graph. The way I've handled this is you enter in the time and respective concentrations, the program then finds out what the slopes would be between each of the plots on all three of the graphs. Then to make the program easy to use, I want to compare all the slopes for ever consecutive points and output which one is most consistent. I initially did this by outputting the slopes to a list and then using the variance command. However, when testing the program I realized I had made a huge blunder seeing as if the graph of [A] versus t produces extremly small slopes (on the order of 10^5) but deviate further from the slope of a straight line as compared to if a graph of say ln[A] versus t produced a vary straight line but has smaller slopes (on the order of 10^2) than if you assume that the most accurate line is the one with the least variance you will be lead astray since the small slopes but less straight graph will give you a small (on the order of 10^5) value of variance compared to the more linear graph. Does anyone know how I would go about using the slopes to calculate how far they deviate from a straight line and then output the result with 0 (zero) signifying a perfectly straight line and anything greater then zero signifying increasing curvature? One way I though of was using:
Code: abs(0mean(d)/median(d)) //d is the list holding the slopes
This worked however I'm not sure that it will work for all cases. Any input would be great. Sorry for the lengthy description/explanation. In case any of you want to play with the program I've included the full source code below. Thanks in any help you can give me, it's greatly appreciated.
Ian B.
FULL CODE:
Code: rates()
Prgm
ClrIO
1>c
Loop
Dialog
Title "Integrated Rate Laws"
Request "Time",x,0
Request "[A]",y,0
Text "Enter x for Time to denote end."
EndDlog
expr(x)>x
expr(y)>y
If x="x" Then
Goto end
EndIf
If c=1 Then
[[x,y]]m
c+1>c
Else
augment(m;[[x,y]])m
EndIf
EndLoop
Lbl end
1>f
Lbl fuction
If f=1 Then
Define g(s)=s
ElseIf f=2 Then
Define g(s)=ln(s)
ElseIf f=3 Then
Define g(s)=1/s
Else
Goto exitp
EndIf
1>c
For i,1,rowDim(m)1
If c=1 Then
{(g(m[2,2])g(m[1,2]))/(m[2,1]m[1,1])}d
c+1>c
Else
augment(d,{(g(m[i+1,2])g(m[i,2]))/(m[i+1,1]m[i,1])})d
EndIf
EndFor
Output (f1)*10,50,approx(abs(0mean(d)/(median(d))))
f+1>f
Goto fuction
Lbl exitp
Output 0,0,"Zero"
Output 10,0,"First"
Output 20,0,"Second"
DelVar c,m,x,y,t,d,i,f,g
EndPrgm
