update (19/12/2016)
Advanced programma's .(69e-71e)
69e) The viscosity (mu) and distance (y)between two parallel plates(laminar flow,heated)
info:staat tussen de code zoals weergegeven op de startpagina.
Application : ref : Basics of the finite element method
Solid Mechanics,Heat Transfer and Fluid Mechanics
Paul E.Allaire (pg 198)
algo : leastsquare method
mu = viscosity , y= distance
find : (a0,a1,a2) ' mu(y)=a0*y^2+a1*y^2+a2 '
download code:VISCOSITYTEMPERATUREDISTANCEFROMWALLFINAL
output view: viscositydistancefinalwithoutgraphics
70e) Viscous fluid flow between parallel plates(finite element method,see 69e))
info:staat tussen de code zoals weergegeven op de startpagina.
Application : ref : Basics of the finite element method
Solid Mechanics,Heat Transfer and Fluid Mechanics
Paul E.Allaire (pg 197-205)
equation : d/dy(mu(y)*du/dy) - dp/dx = 0 , 0<y<h
example: h=.3 ft ,dp/dx = -2e-5 lb/ft^3
x= distance,y= distance,p=pressure,u=velocity
boundary condition (=bc) : bottom ( y=0, 80 °F), u(0) = 0)
top ( y=h,200 °F), u(h) =0)
find : profile:velocity ' u=u(y) '
Maxima :find coefficient of power series.
download code:findcoefpolynomial
output view:findcoefpolynomial
Maxima :find coefficient from the power series after integration (needed for 'truebasic code').
download code:polynomialfindcoefneededforintegration
output view:polynomialfindcoefneededforintegration
A: Linear Elements (Maxima,TrueBasic)
download code:linearfiniteelementfinalfinal
output view:Maximalinearelementsoutput
first part : Derivation of Element Equations
download code:viscousfluidflowparallelplatesshowelfinal.tru
output view: showelementmatrixfluidviscous
Second part : Velocity profile (without graphics)
download code: VISCOUSFLUIDFLOWPARALLELPLATESVELOCITYPROFILEVERSION1FINAL
output view: viscousfluidvelocityprofilefinal
: Velocity profile y(u) (with graphics)
download code:VISCOUSFLUIDFLOWPARALLELPLATESvelocityprofileversion1finalwithgraphicsfinal
output view:viscousfluidflowparallelplatesgraphicsprofileversion1
B:Quadratic Elements (Maxima,TrueBasic)
first part :
download code:quadraticfiniteelementfinalfinal
output view:Maximaquadraticelementsoutput
? How to build : 'stiffness matrix' from a 'number of blocks ' with 3 by 3 dimension .(TrueBasic)
! principle :
download code:copymatainmatbquadraticelementfinal
! sub version:
download code:copymatainmatbquadraticelementfinalsubfinal
output view:copymatainmatbquadraticelementfinaloutputview.png
? How to build : 'stiffness vector' from a 'number of blocks ' with 3 by 1 dimension .(TrueBasic)
! principle :
! sub version:
download code:copyvecainvecbquadraticelementfinalsubfinal
output view:copyvecainvecbquadraticelementfinalsubfinaloutputview.png
Second part : Velocity profile (without graphics)
download code:QUADRATICELEMENTFLUIDFLOWfinalfinal
output view:QUADRATICELEMENTFLUIDFLOWfinalfinaloutputview.png
71e) Relation between two connected Lakes ( pollution problem)
discrete : first-order nonhomogeous dynamical system
------------------------------------------------------------------------------------
amount pollution => simplification to understand principles.
Lake Ontari:a(n) =>0.3 (eq2)
Lake Eri :b(n) =>0.1 (eq1)
Lake Ontario '3' times Lake Eri (=ref)
MODEL:
initial : a(0) = 3*b(0)
a(n+1)=0.87*a(n)+0.38*b(n) '1'
b(n+1)=0.62*b(n) '2'
solution : a(k) = c1*(0.87)^k+c2*(0.62)^k
a(k) = general solution + particular solution
rem : k= number of years > 0
? a(k)
? How to find c1,c2
? How to get eq2
file:pollutionlakemaximamodelsolvefinal.wxmx
intro :
code(Maxima):pollutionlakemaximaintrofinal
code ( html) :pollutionlakemaximaintrofinalhtml
model,solve :
eq1:b(k): 0.1=0.62^k
eq2:a(k): 0.3=4.52*0.87^k-1.52*0.62^k
code(Maxima):pollutionlakemaximamodelsolvefinal
code ( html) :pollutionlakemaximamodelsolvefinalhtml
MODEL: (alternate approach)
=> 'Second-order linear equation'
p1*a(n+2)+p2*a(n+1)+p3*a(n) = 0
=> 'quadratic equation'
a(n+2) = x^2
a(n+1) = x
a(n ) = 1
p1*x^2+p2*x+p3*1 = 0,solve => give:a(k)
x1=0.87,x2=0.62
find :c1,c2 => a(0) = value1,a(1)=value2
code(Maxima):pollutionlakemaximamodelsecondorderlinfinal
code ( html) :pollutionlakemaximamodelsecondorderlinfinalhtml
find : a(1) ?,when a(0) =3
a(k)=4.52*0.87^k-1.52*0.62^k
= > a(1)=3.142
p1= 5000,p2=-7450,p3=2697
a(k)=c1*0.87^k+c2*0.62^k
a(k)=5.127999999999997*0.87^k-2.127999999999997*0.62^k
code(Maxima,update):pollutionlakemaximamodelsecondorderlinfinalupdate1
code ( html,update) :pollutionlakemaximamodelsecondorderlinfinalupdate1html
Modelling
Basis programma's voor analytical chemistry
ref :Chemical Principles
Steven S.Zumdahl
isbn :0618372067
intro :general pratical
diluted solutions 'Maxima'
products : 'flask 1:acid sulfuric+flask 2 : aqua' in other flask
code(Maxima):dilutedsolutionmaximaversion1
code ( html) :dilutedsolutionmaximaversion1html
intro :general log concentration diagram versus pH
code(truebasic):logconcentrationdiagramintroversion1nographfinal
code ( html) :logconcentrationdiagramintroversion1nographfinalhtml
outputview :logconcentrationdiagramintroversion1nographfinaloutput
intro :general ions in Solution
a=f*[conc)
a = activity
f = activity coefficient -> EDHE
conc = concentration (true : conc 1e-2 M,1e-3 M)
see outputview: ( (e)xtend (D)ebye-(H)uckel (e)quation = EDHE)
see outputview: ionic strength
code(truebasic):ionsaqsolfinal
code ( html) :ionsaqsolfinalhtml
outputview :ionsaqsolfinaloutput
intro :general formula for pH
outputview :general pH formula
intro 1: (Maxima), (mono)protic weak acid H(1)A,diprotic weak acid H(2)A.
polyprotic acid : general pH formula (Cb=0,n=1,2,3,4)
code(Maxima) :diproticweakacidsgeneralequationsmaxima
outputview (diprotic) :introdiproticweakacidpart1
outputview (monoprotic):intromonoproticweakacidpart2
(tri)protic weak acid H(3)A :
code(Maxima):triproticweakacid
(tetra)protic weak acid H(4)A :
code(Maxima): tetraproticweakacid
(poly)protic acid : mono ( n=1),di ( n=2),tri (n=3),tetra ( n=4)
rem : di (n=2) => k2=0 => mono(n=1)
general :coef H(n)A :(doc:) coef
:(output:) coefoutput
intro 11: (Maxima), (mono)protic strong acid H(1)A,diprotic strong acid H(2)A.
polyprotic acid : general pH formula (Cb=0,n=2)
code(Maxima) :strongacidfinal
code(txt) :strongacidtxtmaxima
outputview part1:strongacidfinalpart1
outputview part2:strongacidfinalpart2
outputview part3:strongacidfinalpart3
outputview part4:strongacidfinalpart4
outputview part4:strongacidfinalpart5
polyprotic acid : general pH formula (Cb=0,n=3),triprotic strong acid H(3)A.
code(Maxima) :strongacidfornequalto3final
outputview part1:strongacidfornequalto3finalpart1
outputview part2:strongacidfornequalto3finalpart2
intro 2: (Maxima), polyhydroxy base M(OH)n, n=1,2,3.
polyhydroxy base : general pH formula (Ca=0,n=1,2,3)
M(OH)2: ( n=2),dihydroxybase
code(Maxima) :dihydroxybase
outputview :dihydroxybaseoutput
M(OH)3: ( n=3),trihydroxybase
code(Maxima) :trihydroxybase
outputview (1) :trihydroxybasepart1maxima
outputview (2) :trihydroxybasepart2maxima
intro 22: (Maxima), (mono)hydroxy strong base M(OH),(di)hydroxy strong base M(OH)2.
polyhydroxy base : general pH formula (Ca=0,n=2)
code(Maxima) :strongbasefinal
code(txt):strongbasetxtmaxima
outputview part1:strongbasefinalpart1
outputview part2:strongbasefinalpart2
outputview part3:strongbasefinalpart3
outputview part4:strongbasefinalpart4
outputview part5:strongbasefinalpart5
outputview part6:strongbasefinalpart6
polyprotic base : general pH formula (Ca=0,n=3),trihydroxy strong base M(OH)3.
code(Maxima) :strongbasefornequalto3final
outputview part1:strongbasefornequalto3finalpart1
outputview part2:strongbasefornequalto3finalpart2
outputview part3:strongbasefornequalto3finalpart3
intro 3: (Maxima), salt (= weak base (p) + weak acid(q)),c=ca=cb.
general pH formula :
M(p)A(q) -> p*M(x+)+q*A(y-) neutral => p*(x(+))+q*(y-))=0
p -> i=1..p, kb1,kb2,..kbp
q -> i=1..q, ka1,ka2,..kaq
example : (p=1,q=1 => NH4(1)Ac(1) = NH4Ac,c=ca=cb,ka1,kb1)
code(Maxima) :saltweakbaseandweakbase2weakacid1final
outputview part1:saltweakbaseandweakbase2weakacid1finalpart1
outputview part2:saltweakbaseandweakbase2weakacid1finalpart2
(Maxima), salt (= strong base (p) + strong acid(q)),c=ca=cb.
general pH formula : p=integer,q=integer
M(p)A(q) -> p*M(x+)+q*A(y-) neutral => p*(x(+))+q*(y-))=0
exception : p=q=integer => pH =7, Example: p=q=1 , Na(1)Cl(1)=NaCl
general : p<>q,p,q => pH = -log(c*(p-q))
code(Maxima) :saltstrongbasepandstrongacidqfinal
outputview part1:saltstrongbasepandstrongacidqfinalpart1
outputview part2:saltstrongbasepandstrongacidqfinalpart2
(Maxima), salt (= strong base (p) + weak acid(q)),c=ca=cb.
example :NaAc,p=1,q=1,test=p*(1)+q*(-1)=0,neutral charge
( strong base = NaOH ,weak acid = HAc,ka1)
general pH formula : p=integer,q=integer
M(p)A(q) -> p*M(x+)+q*A(y-) neutral => p*(x(+))+q*(y-))=0
definition : kh = hydrolysis equilibrium constant. (see : outputviewpart2)
code(Maxima) :saltstrongbasepandweakacidqfinal
outputview part1:saltstrongbasepandweakacidqfinalpart1
outputview part2:saltstrongbasepandweakacidqfinalpart2
(Maxima), salt (= weak base (p) + strong acid(q)),c=ca=cb.
example :NH4Cl,p=1,q=1,test=p*(1)+q*(-1)=0,neutral charge
( weak base = NH4OH ,weak acid = HCl,kb1)
general pH formula : p=integer,q=integer
M(p)A(q) -> p*M(x+)+q*A(y-) neutral => p*(x(+))+q*(y-))=0
definition : kh = hydrolysis equilibrium constant. (see : outputviewpart2)
code(Maxima) :saltweakbasepandstrongacidqfinal
outputview part1:saltweakbasepandstrongacidqfinalpart1
outputview part2:saltweakbasepandstrongacidqfinalpart2
intro 4: (Maxima), mixture of 'weak acids' or 'weak bases'.
principal : superposition ( = charge balances of species)
'weak acids' =
[H(+)]tot = [H(+)]'aq'+[H(+)]'HA1'+[H(+)]'HA2'
'weak bases' =
[OH(-)]tot = [OH(-)]'aq'+[OH(-)]'M1OH'+[OH(-)]'M2OH'
code(Maxima) :mixtureacidsorbasefinal
outputview part1:mixtureacidsorbasefinalpart1
outputview part2:mixtureacidsorbasefinalpart2
outputview part3:mixtureacidsorbasefinalpart3
code(TrueBasic) :mixturetwoweakacidstruebasicfinal
code(html ) :mixturetwoweakacidstruebasicfinalhtml
outputview :mixturetwoweakacidstruebasicfinaloutput
intro 5: (Maxima), amphoteric salt,MHB -> M(+)+HB(-)
[H(+)]tot = [B(2-)]-[H(2)B]+[0H(-)],ka1,ka2,[HB(-)]
code(Maxima) :amphotericsaltphfinal
outputview part1:amphotericsaltphfinalpart1
outputview part2:amphotericsaltphfinalpart2
outputview part3:amphotericsaltphfinalpart3
code(TrueBasic) :amphotericsaltphfinal
code(html ) :amphotericsaltphfinalhtml
outputview :amphotericsaltphfinaltrueoutput
intro :general regression (linear y=aa*x+bb,version 1.0,1a),truebasic
code(TrueBasic,1.0) :REGRESSIONREALWORLDNEWfinalversion1
code(html ,1.0) :REGRESSIONREALWORLDNEWfinalversion1html
outputview,1.0 :REGRESSIONREALWORLDNEWfinalversion1output
! to draw graph with data x,y (in general)
code(TrueBasic,1a) :REGRESSIONREALWORLDNEWfinalversion1a
code(html ,1a) :REGRESSIONREALWORLDNEWfinalversion1ahtml
outputview,1a:REGRESSIONREALWORLDNEWfinalversion1aoutput
intro :general sort parallel arrays (2d,matrix),truebasic
code:PARALLELSORTarrayfinal
code(html):PARALLELSORTarrayfinalhtml
outputview:PARALLELSORTarrayfinaloutput
intro :general aspect ratio (draw circles on a graph),truebasic
code:aspectratiographdrawfinalversion1
code(html):aspectratiographdrawfinalversion1html
outputview:aspectratiographdrawfinalversion1output
=========================
1e) titration curve :strong acid (HCl) + strong base (NaOH) 'Truebasic'
pH = - log[H+] , pOH+pH = 14
reaction : HCl + NaOH -> NaCl + aq
code:phstrongacidwithstrongbasefinalversion1
outputview :phstrongacidwithstrongbasefinalversion1output
code:PHSTRONGACIDWITHSTRONGBASEFINALVERSION1a
outputview :PHSTRONGACIDWITHSTRONGBASEFINALVERSION1aoutput
2e) titration curve: weak acid (HAc) + strong base (NaOH) 'Truebasic'
pk_a + pk_b =14 =pk_w
reaction : HAc + NaOH -> NaAc+ aq
code:PHweakACIDWITHSTRONGBASEfinalversion1a
outputview :PHweakACIDWITHSTRONGBASEfinalversion1aoutput
3e) titration curve: base 'salt' (Na(2)CO3) + strong acid (HCl) 'Truebasic'
ka1,ka2 -> kb1,kb2 (see inside the code,2e)
reaction : Na(2)CO3 + HCl -> NaHCO3 + NaCl
NaHCO3 + HCl -> H(2)CO3 +NaCl
code:PHbasesaltWITHSTRONGacidfinalversion1a
outputview :PHbasesaltWITHSTRONGacidfinalversion1aoutput
4e) species present in solutions of polyprotic acid 'Truebasic'
print "************************************************"
print " polyprotic acid: H(2)S = H(+) + HS(-) => ka(1) "
print " HS(-) = H(+) + S(2-) => ka(2) "
print "************************************************"
print " general : polyprotic acid ,m=n-1 => H(m)A ,m=2 "
print "************************************************"
print " (di)protic acid : n=3,m=2 (see code) "
print " sum = (H[+])^2+ka(1)*H[+] + Ka(1)*ka(2) "
print " C= [H(2)S]+[HS(-)]+[S(2-)] "
print " alpha(0) = (H[+])^2/ sum = [H(2)S]/C "
print " alpha(1) = ka(1)*H[+]/sum = [HS(-)]/C "
print " alpha(2) = Ka(1)*ka(2)/sum = [S(2-)]/C "
print " check = alpha(0)+alpha(1)+alpha(2)=1 "
print "************************************************"
code:fractioncalanalyticalspeciesversion1
code ( html) :FRACTIONCALANALYTICALSPECIESVERSION1html
outputview :fractioncalanalyticalspeciesversion1output
5e) pH calculation of weak polyprotic acid 'Truebasic'(see 4e)
example : (di)protic acid = ' [H(2)S] '
given : ka(1), CZ, [OH(-)] = kw/[H(+)]
!*******************************************************
! use : charge balance ( general use S=A : why H(m)A)
! Positive ion species : [H(+)]
! Negative ion species : [HS(-)],[S(2-)],[OH(-)]
!*******************************************************
[H(+)] = [HS(-)]+[S(2-)]+[OH(-)]
!*******************************************************
build :
second_approx_h ' (see below sub) in code'
[H(+)] = alpha(1)*CZ+2*alpha(2)*CZ+[OH(-)] *
!*******************************************************
! to use above* : first approximation [H+]
!*******************************************************
[H(+)] = sqr(ka(1)*CZ) to => CVG
!*******************************************************
code:FRACTIONCALANALYTICALSPECIESusePHweakacidfinal
code ( html) :FRACTIONCALANALYTICALSPECIESusePHweakacidfinalhtml
outputview :FRACTIONCALANALYTICALSPECIESusePHweakacidfinaloutput
6e) pH calculation (buffer index = Beta) " added strong acid ", 'Truebasic'
print " Beta = dCb/dpH = - dCa/dpH 'buffer index' "
print "************************************************"
print " monoprotic acid: HA = H(+) + A(-) => ka "
print "************************************************"
! HA = monoprotic weak acid ( example = HAc )
print "******************************************************"
print "* ka = ([H(+)][A(-)])/[HA] (1) *"
print "* Cb = moles NaOH = [Na(+)],Ca = moles HCl = [Cl(-)] *"
print "* C = [HA]+[A(-)] (2) *"
print "* (1) and (2) [A(-)] = C*ka/([H(+)]+ ka) (3) *"
print "******************************************************"
print " Charge Balance : *"
print "******************************************************"
print "[H(+)]+[Na(+)] = [OH(-)]+[Cl(-)]+[A(-)] (4) *"
print " Cb=Ca+kw/[H(+)]-[H(+)]+C*ka/([H(+)]+ ka) (5) *"
print "******************************************************"
print " rem : pH = - log(10)[H(+)] = -1/ln(10) * ln[H(+)] *"
print " *****************************************************"
print " Beta = dCb/dpH = dCb/d[H(+)]*d[H(+)]/dpH "
print "***********************************************************"
code(maxima):bufferindex
outputview(maxima) :bufferindexoutput
print "*Beta = ln(10)*(kw/[H(+)]+[H(+)]+C*ka*[H(+)]/(ka+[H(+)])^2) *"
print "***********************************************************"
print " del_pH = -del_Ca/Beta "
print "***********************************************************"
print " pH=pka + log([HA])/([A(-)]) + del_pH =pH_buffer + del_pH "
print "***********************************************************"
general: Definition " Buffer index of polyprotic acids 'weak acid' , H(n)A"
Beta = ln(10)*(kw/[H(+)]+[H(+)]+ sum(C*ka(i)*[H(+)]/(ka(i)+[H(+)])^2) ,i,1,n))
example : n=3, H(3)PO4
code:BUFFERINDEXWEAKACIDVERSUSSTONGACIDFINALVERSION1
code ( html) :BUFFERINDEXWEAKACIDVERSUSSTONGACIDFINALVERSION1html
outputview :BUFFERINDEXWEAKACIDVERSUSSTONGACIDFINALVERSION1output
7e) theoretical titration curve HCl with NaOH , 'Truebasic'
given :
print "************************************************"
print "* calculation : Theoretical :titrated v0=50ml *"
print "* of c0=0.1M HCl with V ml of c=0.1M Na0H. *"
print "* definition : phi = (c*v)/(c0*v0),version 1.0 *"
print "************************************************"
result :
print "************************************************"
print "* example : c=c0 => phi = v/50 *"
print " 1e Before EP : phi < 1 :[H(+)]>>>[OH(-)],pH<7 *"
print " 2e EP : phi = 1 :[H(+)]=[OH(-)] ,pH=7 *"
print " 3e after EP : phi > 1 :[OH(-)]>>>[H(+)],pH>7 *"
print "************************************************"
print "************************************************"
print " reaction : HCl + NaOH -> NaCl + H(2)O ,pH =7 "
print " pKw = pOH + pH => [OH(-)] = kw/[H(+)] "
print "************************************************"
print " Charge Balance : "
print "[H(+)]+[Na(+)] = [OH(-)]+[Cl(-)] (1) *"
print " [Cl(-)] = c0*v0/(v0+v) => HCl (2) *"
print " [Na(-)] = c*v/(v0+v) => NaOH (3) *"
print " (c*v-c0*v0)/(v+v0) =[OH(-)] - [H(+)] (4) *"
print " (c0*v0)/(v+v0)*{phi-1) = kw/[H(+)]-[H(+)] (5) *"
print " example : phi = v/50 ,c=c0=.1M *"
print " (.1*50)/(v+50)*{v/50-1) = kw/[H(+)]-[H(+)] (6)*"
print "**************************************************
print " pH = - log(10)[H(+)] = -1/ln(10) * ln[H(+)] *"
print " ************** ***********************************
!*******************************************************
! theoretical:
!*******************************************************
! before EP : acid approximation (curve)
! (c0*v0)/(v+v0)*{1-phi} = [H(+)]
!*******************************************************
! by EP : c0*v0 = c*v
!*******************************************************
! after EP : basic approximation (curve)
! (c0*v0)/(v+v0)*{phi-1} = [OH(-)]=kw/[H(+)]
!*******************************************************
code:Theoreticaltitrationstrongacidwithstrongbaseversion1
code ( html) :Theoreticaltitrationstrongacidwithstrongbaseversion1html
outputview :Theoreticaltitrationstrongacidwithstrongbaseversion1output
8e) Complex formation with a ligand(find :Solubility) , 'Truebasic'
-----------------------------------------------------------------------------------------------------------
print "* find : (S)olubility = S 'AgBr(solid)' *"
print "* calculation : complex formation with a ligand*"
print "* added to the solid. *"
print "* AgBr(solid) solved with NH(3)='ligand'= X *"
print " M(p)A(q):example M = Ag(+),A = Br(-),p=1,q=1 *"
print "* example: AgBr(solid) = Ag(+)+Br(-) Ksp *"
print " Ag(+)+NH(3) = Ag(NH(3))(+) k1 *"
print " Ag(NH(3))(+)+NH(3)= Ag(NH(3))(2)(+) k2 *"
!********************************************************
print " general: k1,k2,k3 to kn (version 1.0) *"
print "***************************************************"
print "* M => beta_c(0) ? *"
print " MX(+) = k1*[M(+)][X],[MX(2)(+)] = k2*[MX(+)][x] *"
print " beta_c(0) = [M(+)]/([M(+)]+[MX(+)]+[MX(2)(+)]) *"
print " example : k1,k2 *"
print " beta_c(0) = 1/(1+k1*[X]+k1*k2*[x]^2) *"
print "***************************************************"
print "********************************************************"
print " general : k1,k2,...kn 'n formations complexes with X' *"
print "beta_c(0) = 1/(1+k1*[X]+k1*k2*[x]^2+..+k1*k2..kn*[x]^n) *"
print "********************************************************"
----------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------
definition : S =(ksp/(p^p*q^q*(beta_c(0) )^p))^(p+q)
beta_c(0) = 1, (no complex formation)
------------------------------------------------------------------------------
code:complexformationwithligandfinalfinal
code ( html) :complexformationwithligandfinalfinalhtml
outputview :complexformationwithligandfinalfinaloutput
code 1.0a:COMPLEXFORMATIONWITHLIGANDFINALFINALversion1a
code 1.0a ( html) :COMPLEXFORMATIONWITHLIGANDFINALFINALversion1ahtml
outputview 1.0a :COMPLEXFORMATIONWITHLIGANDFINALFINALversion1aoutput
9e) theoretical titration curve polyprotic acid (H(m)A) with NaOH , 'Truebasic'
example : diprotic acid 'weak acid'
see : 4e) analytical serie
print "************************************************"
print " polyprotic acid: H(2)A = H(+) + HA(-) => ka(1) "
print " HA(-) = H(+) + A(2-) => ka(2) "
print "************************************************"
print " general : polyprotic acid ,m=n-1 => H(m)A ,m=2 "
print "************************************************"
print " use : alph(1) ,alpha(2),........,alpha(m) "
print "************************************************"
!********************************************************
!********************************************************
! tot_vol = v + vx
!********************************************************
! v = initial volume H(m)A 'before added base vx=0'
! vx = volume of base added from buret
!--------------------------------------------------------
! CA = CA0(v/tot_vol)
!--------------------------------------------------------
!CA0 = molarity initial concentration of H(m)A
!--------------------------------------------------------
! CB = CB0(vx/tot_vol)
!--------------------------------------------------------
!CB0 = molarity of strong base in the buret
!********************************************************
!********************************************************
!*******************************************************
!********************************************************
! charge balance:
! [H(+)] = [HA(-)]+2*[A(2-)]+[OH(-)] (1)
!********************************************************
! [H(+)] = [HA(-)]+2*[A(2-)]+[OH(-)]-CB
! = (H(+))'H(m)A'+(H(+))'aq' -(H(+))'reacted base'
! CB negativ sign use up [H(+)]
!********************************************************
! [H(+)] = alpha(1)*CA+2*alpha(1)*CA+kw/[H(+)]-CB (2)
!********************************************************
! use above : definition CA,CB => solve (2) for 'vx'
!********************************************************
!********************************************************
vx = x ' maxima code ' = added NaOH (solved from (2))
code (maxima):titrationpolyproticacidmaxima
outputview (maxima):titrationpolyproticacidmaximaoutput
!********************************************************
result :
!********************************************************
! vx = ratio = num/denum
!********************************************************
!num = (alpha(1)*CA0+2*alpha(1)*CA0+kw/[H(+)]-[H(+)])*v
!denum = (CB0-kw/[H(+)]+[H(+)])
!********************************************************
!********************************************************
! no graphics
code:TITRATIONGENERALpolyPROTICACIDWITHSTRONGBASEversion1
code ( html) :TITRATIONGENERALpolyPROTICACIDWITHSTRONGBASEversion1html
outputview :TITRATIONGENERALpolyPROTICACIDWITHSTRONGBASEversion1output
! graphics
code1a:TITRATIONGENERALpolyPROTICACIDWITHSTRONGBASEversion1a
code1a ( html) :TITRATIONGENERALpolyPROTICACIDWITHSTRONGBASEversion1ahtml
outputview :TITRATIONGENERALpolyPROTICACIDWITHSTRONGBASEversion1aoutput
10e) Solubility M(p)A(q) in solution (weak anion acid) of certain 'pH' , 'Truebasic'
print "*************************************************"
print "*weak acid : H(m)A(n), 'general n=1' *"
print "*solid : M(p)A(q) *"
print "*************************************************"
use with : anion of weak acid H(m)A (+)
not use with : complex formation
!*****************************
!info: common ion effect , (+)
!*****************************
!*******************************************************
! M(p)A(q) => weak acid anion H(m)A(n) ,'general n=1'
!*******************************************************
! examples : ' precipitate '
!*******************************************************
! 1e) Ca [C(2)O(4)] A = Oxalic anion => alpha(2)
! p=1,q=1,m=2,n=1 => H(2)[C(2)O(4)]
! 2e) Ag(2) S A = Sulfide anion => alpha(2)
! p=2,q=1,m=2,n=1 => H(2)S
! 3e) Ag(3) PO(4) A = Phosphate anion => alpha(3)
! p=3,q=1,m=3,n=1 => H(3)PO4
! 4e) Sr(1)CO(3) A = Carbonate anion => alpha(2)
! p=1,q=1,m=2,n=1 => H(2)CO3
! 5e) Sr(1) F(2) A = Fluoride anion => alpha(1)
! p=1,q=2,m=1,n=1 => HF
! CF = [HF]+[F(-)] => alpha(0)->[HF] and alpha(1)->[F(-)]
! 6e) Ca(3)[PO4](2) A = Phosphate anion => alpha(3)
! p=3,q=2,m=3,n=1 => H(3)PO4
! M(p)A(q) 'solid' : M = Ca(2+) => p , A = PO4(3-) => q
! 7e) Bi(1)PO4 A = Phosphate anion => alpha(3)
! p=1,q=1,m=3,n=1 => H(3)PO4
! 8e) CdS A = Sulfide anion => alpha(2)
! p=1,q=1,m=2,n=1 => H(2)S
!*******************************************************
!*******************************************************
print "***************************************************"
print " polyprotic acid: H(2)A = H(+) + HA(-) => ka(1)
print " HA(-) = H(+) + A(2-) => ka(2)
print " M(p)A(q)'solid' M(p)A(q) = p M(v+)+q A(w-) ksp
print "***************************************************"
print " general : polyprotic acid ,m=n-1 => H(m)A ,m=2 "
print "***************************************************"
print " use : alph(0),alpha(2),..,alpha(m) "
print " use : ka(1),ka(2),..ka(j)...,ka(m) "
print " alpha(i) = f( ka(j),[H(+)]), j=1..m "
print "***************************************************"
print "************************************************"
print " given : pH 'anion acid' "
print "************************************************"
print " Solubility 'S' M(p)A(q)'Ksp' in anion acid "
print " ksp =(p*S)^p*(q*S*alpha(m))^q "
print " S = ( ksp/(p^p*q^q*(alpha(m))^q))^(1/(p+q)) "
print "************************************************"
!*******************************************************
! info : p*v(+)+q*w(-) = 0
!*******************************************************
code:formationofweakacidwithanionprecipitatefinalversion1
code ( html) :formationofweakacidwithanionprecipitatefinalversion1html
outputview :formationofweakacidwithanionprecipitatefinalversion1output
11e) Solubility M(p)A(q) in solution,common ion effect (salt anion ) . 'Truebasic'
example : BaSO4 (solved in Na(2)SO4)
print "****************************************"
print " Solubility M(p)A(q) common ion effect '"
print "****************************************"
print "*calculation : given M(p)A(q)'solid' solved in
print "*anion of the precipitat through MM(n)A(m).
print "*solid : M(p)A(q), 'general n=1'
print "*solved : MM(n)A(m),BaSO4 in Na2SO4
print "*************************************************"
print "use with:common anion (salt of anion ) "
print "not use with:complex formation,anion of weak acid "
print "*************************************************"
!*******************************************************
! M(p)A(q) => (salt) anion MM(m)A(n 'general n=1'
!*******************************************************
! examples : ' precipitate '
!***************************************************"
! 1e) BaSO4 ( anion salt ' Na(2)SO4,concentration = C)
! p=1,q=1,m=2,n=1
!***************************************************"
print "**********************************************"
print " given : concentration 'salt anion' = C "
print "**********************************************"
algo :
!*****************************************************
! first approximation S1
S1 = (ksp/(p^p*(n*C)^q))^(1/p) (1)
Solubility 'S' M(p)A(q)'Ksp' in anion salt
ksp =(p*S)^p*(q*s + n*c)^q
S=( ksp/(p^p*(n*C)^q*(1+((q*s)/(n*C)))^q))^(1/p) (2)
! second approximation ,third approximation ...... (1) in (2)
! first approximation (1) in(2)
!second approximation (2) in(2)
!third approximation (2) in(2)
!*****************************************************
code:commonioneffectsolidwithanionversion1final
code ( html) :commonioneffectsolidwithanionversion1finalhtml
outputview :commonioneffectsolidwithanionversion1finaloutput
12e) draw: species present in solutions of polyprotic acid 'Truebasic' .
info : see 4e,5e above.
use : to draw graphics in general.
code:DRAWDISTRIBUTIONPHVERSUSSPECIESTversion1final
code ( html) :DRAWDISTRIBUTIONPHVERSUSSPECIESTversion1finalhtml
outputview :DRAWDISTRIBUTIONPHVERSUSSPECIESTversion1finaloutput
13e) draw: precipitation curve of insoluble AgCl 'Truebasic' .
use : to draw graphics in general.
reaction : NaCl+AgNO3 -> AgCl 'solid' + NaNO3 'titration'
print "***********************************"
print "* precipitation curve AgCl,version 1.0 *"
print "* use: ksp=[Ag(+)][Cl(-)]=10^(-10) *"
print "* => pAg+pCl = -log(10)(10^(-10)) = 10 *"
print "***********************************"
print "* titration curve:draw(x ml AgNO3,pAg) *"
print "* 1e) before EP => [Cl(-)] -> [Ag(+)] *"
print "* 2e) by EP => [Cl(-)] = [Ag(+)] *"
print "* 3e) after EP => excess [Ag(+)] *"
print "***********************************"
print "* buret : x ml AgNO3 0.1N to *"
print "* erlenmeyer flask:(NaCl 10 ml 0.1N) *"
print "***********************************"
code:precipitationcurveagclfinalversion1
code ( html) :precipitationcurveagclfinalversion1
outputview :precipitationcurveagclfinalversion1output
14e) draw: redox titration for (Fe(2+)/Ce(4+)), 'Truebasic' .
use : to draw graphics in general.
reaction : Fe(2+)+Ce(4+) -> Fe(3+) +Ce(3+) 'titration'
print "* E = Eo+0.059/n log([Ox]/[Red]) *"
print "*[Ox] = must be reduced (Fe(3+) -> Fe(2+)) *"
print "*[Red]= must be oxidated (Fe(2+) -> Fe(3+)) *"
print "* Eo = reduction potential (table) *"
print "* titration curve:Fe(2+)/Ce(4+),a=1,b=1 *"
print "*********************************************"
print "*Before:EP,E=Eo(Fe)+0.059/a*log([Fe(3+)]/[Fe(2+)]) *"
print "*By:EP => E_eq =(Eo_Fe*a+Eo_Ce*b)/(a+b) *"
print " after :EP E=Eo(Ce)+0.059/b*log([Ce(4+)]/[Ce(3+)]) *"
print "*********************************************"
print "*********************************************"
print "* buret : x ml Ce(4+) 0.1N *"
print "* erlenmeyer flask:(Fe(2+) 10 ml 0.1N) *"
print "*********************************************"
code:redoxtitrationfe2ce4tfinalversion1
code ( html) :redoxtitrationfe2ce4tfinalversion1html
outputview :redoxtitrationfe2ce4tfinalversion1output
15e) theoretical titration (M(n+) with EDTA =>Y(4-) ), 'Maxima'
code:ComplextritrationEDTAmetaalmaxima
code (outputview, html) :ComplextritrationEDTAmetaalmaximahtml
16e) kfc=(c)onditional (f)ormation(c)onstant,alpha4(pH), 'Truebasic,Maxima'
use : to draw graphics in general.
n =integer,1,2,3,4
print "*********************************"
print " M(n+)+Y(4-) <-> MY(n-4),M=metal "
print " kf = [MY(n-4)]/([M(n+)]*[Y(4-))] "
print "*********************************"
print "******************************************"
print "*kfc = kf*alpha4=MY(n-4)/([M(n+)]*[EDTA]) *"
print "******************************************"
'Truebasic',alpha4 :see code
code:correctionfactorformationconstantkfcfinal
code (html) :correctionfactorformationconstantkfcfinalhtml
outputview:correctionfactorformationconstantkfcfinaloutput
'Maxima',(show :combination sum and product in Maxima)
code:alpha4maximafinal
code (html) :alpha4maximafinalhtml
17e) kfcc=(c)onditional, (f)ormation,(k)onstant ,ligand formation'Truebasic'
use : to draw graphics in general.
n =integer,1,2,3,4
print "*********************************"
print " M(n+)+Y(4-) <-> MY(n-4),M=metal "
print " kf = [MY(n-4)]/([M(n+)]*[Y(4-))] "
print "*********************************"
print "******************************************"
print "*kfcc= kf*alpha4*betaL=MY(n-4)/(C_M*C_EDTA) *"
print "******************************************"
number of ligands = 2 -> ML2(n+)
concentration of ligand = L
betaL =(kfl(1)*kfl(2))/(1+[L]*kfl(1)+kfl(1)*kfl(2))
code:kfccfinalversion1
code (html) :kfccfinalversion1html
outputview:kfccfinalversion1output
18e) (bi)modal fit 'conductometric titration version 1.0 (NaOH to HCl)', 'Truebasic'
see also :intro :general regression (linear y=aa*x+bb,version 1.0,1a),truebasic,above
see also :intro :general sort parallel arrays (2d,matrix),truebasic,above
bron :data:https://plot.ly/~ramesh.ammanamanchi/25/conductometric-titration-curve/
code:conductometrictitrationdataversion1final
code (html) :conductometrictitrationdataversion1finalhtml
outputview:conductometrictitrationdataversion1finaloutput
19e) (tri)modal fit ' (labo experiment)', 'Truebasic'
rem : tri ,three parts ( = segmentation=seg=3) of fitting with lines.
see also : 18e) => (= segmentation= seg=2) of fitting with lines.
!*********************************************
! math : find minimum qp,'least square method'
!*********************************************
example: see inside the code ,algo trimodal fit (seg =3)
!*********************************************
!number of segments =>'n = number of(x,y)data'
!*********************************** number***
! seg = 1 => y1
!*********************************************
! seg = 2 => ,for loop (1)
! ( 1 -> p,p+1-> n) ,y1,y2
! loop 1: for p=2 to n-2=n-(seg-1)*2 => p
!*********************************************
! seg = 3 => ,for loop (2)
! ( 1->p,p+1->q,q+1->n) ,y1,y2,y3
! loop 1: for p=2 to n-4=n-(seg-1)*2 => p
! loop 2: for q=p+2 to n-2=n-(seg-2)*2 => q
!********************************************
! seg = 4 => ,for loop (3)
! ( 1->p,p+1->q,q+1->r,r+1->n) ,y1,y2,y3,y4
! loop 1: for p=2 to n-6=n-(seg-1)*2 => p
! loop 2: for q=p+2 to n-4=n-(seg-2)*2 => q
! loop 3: for r=q+2 to n-2=n-(seg-3)*2 => r
! etc....
!********************************************
!********************************************
result : version (1.0 =1a ) => (see : outputview)
with : sort algorithm,find minimum 'qp'
code(version 1.0) :TRIMODALFITFINALVERSION1
code (html,version 1.0) :TRIMODALFITFINALVERSION1html
outputview(version 1.0):TRIMODALFITFINALVERSION1output
without : sort algorithm,find minimum 'qp' =optimize (with qpmin)
code(version 1a) :TRIMODALFITFINALVERSION1aoptimizefinal
code (html,version 1a) :TRIMODALFITFINALVERSION1aoptimizefinalhtml
outputview(version1a):TRIMODALFITFINALVERSION1aoptimizefinaloutput
REM : angle between two lines ( example: angle(y1,y2),angle(y2,y3) ).
code(version 1a) :findanglebetweentwolinesversion1final
code (html,version 1a) :findanglebetweentwolinesversion1finalhtml
outputview(version1a):findanglebetweentwolinesversion1finaloutput
========================================
Basis programma's voor simulaties in chemical engineering.
chem mod 1: differential equation
model : difmod
output view: difmodview
chem mod 2: gravity flow tank
model : gravmod
output view: gravmodview
chem mod 3: three CSTRS in serie
model : threecstrs
output view: threecstrsview
Chemical equation solving:
intro 1 : decimal to fraction
code :decimaltofractionerrorcontrolfinalsubfinal.tru 'see below'
output view:dectofracsubfinalfinalfinal
option nolet
!********************************************************
!********************************************************
! file : decimaltofractionerrorcontrolfinalsubfinal.tru
!********************************************************
!********************************************************
print "********************************************************"
print "* decimal to fraction version 1.0a *"
print "* [email protected],10/03/2106 *"
print "********************************************************"
print "* with error control,epsilon (sub version) *"
print "********************************************************"
!************************************************
! future : sub dec_frac
!************************************************
! ref : Computational Mathematics B.P Demidovich
! Mir PUBLISHERS MOSCOW pg 55... ( example pg 61)
!************************************************
print "***********************************************************"
print " Example : find pi:3.14159 ? 22/7 : give in 'number = 1' "
print "***********************************************************"
epsilon =0.01
input prompt " Example = '1' , Choose = '2' => ":no
print "***********"
print "* input = *"
print "***********"
if no = 1 then
nu =3.14159 ! pi =3.14159
print " pi : 3.14159 "
else
input prompt " Real Number(example = 45.1256) = ":nu
input prompt " epsilon (example = 0.0001 ) = ":epsilon
if epsilon = 0 then
epsilon = 0.01
end if
end if
call dec_frac(nu,tel,noem,remain,epsilon,error)
print "***********"
print "* output =*"
print "***********"
print "************"
print " values => "
print "************"
print " epsilon = ";epsilon
print " error = ";error
print " nominator = ";tel
print " denominator = ";noem
print " remainder = ";remain
print "************"
print "* result = *"
print "************"
if nu = 1 then
print " pi :3.14159 == ";tel;"/";noem
print " => find real value : ";tel/noem
else
print nu;" == ";tel;"/";noem
print " => find real value : ";tel/noem
end if
end
sub dec_frac(nu,tel,noem,remain,epsilon,error)
dim a(0 to 1000),y(0 to 1000),r(0 to 1000)
dim p(-1 to 1000),q(-1 to 1000)
n=1000
do
k=0
a(k)=int(nu)
r(k)= nu - a(k)
if r(k) <> 0 then y(k)=1/r(k)
!********************************************
!********************************************
! p(k),q(k) second order difference equations
! p(k),q(k) two initial conditions for each
!********************************************
p(k) = a(k)
p(-1) = 1
q(k) = 1
q(-1) = 0
ratio = p(0)/q(0)
!********************************************
error = abs(nu-ratio)
before_ratio = ratio
k=1
a(k)=int(y(0))
r(k)= y(0) - a(k)
if r(k) <> 0 then y(k)=1/r(k)
p(k) = a(k)*p(0)+p(-1)
q(k) = a(k)*q(0)+q(-1)
ratio = p(k)/q(k)
error = abs(ratio-before_ratio)
if error < epsilon then exit do
before_ratio = ratio
for k=2 to n
a(k)=int(y(k-1))
r(k)=y(k-1)-a(k)
if r(k)<> 0 then y(k)=1/r(k)
p(k) = a(k)*p(k-1)+p(k-2)
q(k) = a(k)*q(k-1)+q(k-2)
ratio = p(k)/q(k)
error = abs(ratio-before_ratio)
if error < epsilon then exit do
before_ratio = ratio
next k
loop
remain=r(k-1)
tel = p(k-1)
noem = q(k-1)
end sub
intro 2 : decimal to fraction ( sums of fractions )
code :decimaltofracstudiesumfinalfinalversion1bfinal.tru
output view:decimaltofracstudiesumfinalversion1bfinal
intro 3 : number (=integer) factoring into primes
code :DIVISIONPRIMES2002sub2016finalversion1.tru
output view:numberintoprimesfactors
intro 4 :reaction needed for material balances from a set of reactions (Maxima,"echelon" )
code :reactionfromchemicalprocess
code (version 1.0) :materialbalancefinalversion1
output view:reactionfromchemicalprocess.png
code (Maxima " for,if,sum" )
kill(all)$
given: print("2*x-5*y+3*z+5*u=0 ");
kk:[x,y,z,u]$
for i:1 step 1 thru length(kk) do
v[i]:0$
t:-2*x-5*y+3*z+5*u=0;
for i:1 step 1 thru length(kk) do
k[i]:coeff(lhs(t),kk[i])$
for ii:1 step 1 thru length(kk) do
if k[ii] < 0 then
v[ii]:k[ii]*kk[ii]$
tt:sum(v[ii],ii,1,length(kk));
result1 : print ("tt =-5*y-2*x");
tl:lhs(t)-tt$
tr:rhs(t)-tt$
tl=tr;
result2 :print("3*z+5*u=5*y+2*x");
code: equationpartchangefromlefttoright
code (Truebasic )
code:equationpartchangefromlefttorightfinalversion1
code:equationpartchangefromlefttorightfinalversion1a
outputview :equationpartchangefromlefttorightfinalversion1output
=======================