kill(all);

Maxima : intro computation ,base and acid, 'part :5,version 1.0'
peter.vlasschaert@gmail.com, 27/11/2018

load packages :
------------------------

load(lrats)$

convert:
-----------

log10(x):=log(x)/log(10);

definition : pH,pOH
================

p1: pH(x)   :=-log10(x)$
p1a:pOH(x):=-log10(x)$

dissociation : aq :
===============

kw:10^(-14);

quadratic equation :  s1*x^2+s2*x+s3= 0
=================

quadra2(s1,s2,s3,aa):= block([x1,x2,disc], disc: sqrt(s2^2-4*s1*s3),
                                                     x1:(-s2+disc)/(2*s1),
                                                     x2:(-s2-disc)/(2*s1),
                                                     aa:[x1,x2])$  

rem:solution of quadratic equation ,only pos solution have a physical meaning.

Weak base: B
================

example : methylamine,kb = 5.0*10^(-5)
pkb = -log10(kb)

reaction : B+H(2)O ⇔ BH(+) + OH(-)          ....  '1'
rem: OH(-) =OH, BH(+) = BH

equilibrium:

definition : pKb
============

p2:pKb(x)   :=-log10(x)$

definition : K_b      .... '2'
============

p2a:K_b = ((BH)*(OH))/(B);

C_B = concentration weak Base  ... '3'
----------------------------------------------

p3:C_B=(B)+(BH);

from : '1' follows :  OH=BH  ... '4'
--------------------------------

p3a:BH=OH;

p3b:subst([p3a],p3);

result:  B  ... '5'
--------

p3c:solve(p3b,B)[1];

insert : '3' and '4' into  '2'
-----------------------

p4:subst([p3a,p3c],p2a);

p4a:part(rhs(p4),1);

p4b:part(rhs(p4),2);

p4c:p4*p4b;

p4d: rhs(p4c) - lhs(p4c)=0;

quadratic equation:s1*x^2+s2*x+s3= 0 ,... '5'
---------------------------.

p4e:expand(p4d);

find:si ,i=1,2,3
--------------------

p4f:args(lhs(p4e));

p4g:[OH=1];

s1:subst(p4g,p4f[1]);
s2:subst(p4g,p4f[2]);
s3:subst(p4g,p4f[3]);

solve quadratic:'5'
============

p6:quadra2(s1,s2,s3,aa);

rem:solution of quadratic equation ,only pos solution have a physical meaning.

assume(C_B>0,K_b>0);

check : solutions of physical meaning
---------------------------------------------------

p6a:is(p6[1]>0);

p6b:is(p6[2]>0);

function : physical meaning: phsysicalm(sol,number)
-------------------------------------

physicalm(f1,jj):=is(f1[jj]>0);

p6a1:physicalm(p6,1);

p6b1:physicalm(p6,2);

p6a = p6a1, p6b=p6b1 , general use , physical meaning.

How to find, [OH] =OH , 'concentration of weak base'.
=====================================

physicalsol(K_b,C_B,sol):=

find OH: with function.  physicalsol(K_b,C_B,sol)
------------------------------------------------------------------
rem :sol is here 'p6'

p7:if physicalm(p6,1) =true then p6[1];

p7aΑ:for i:1 thru 2 do(
if physicalm(p6,i) =true then ss:p6[i]);

ss;

function : symbolic solution
========================

p7b:physicalsol(sol,s):=block(for i:1 thru 2 do(
if physicalm(sol,i) =true then s:sol[i]),return(s));

symbolic : sol
--------------

p8:physicalsol(p6,s);

p8a:OH = p8;

rem:block and return are connected with in function, 'physicalsol'

function : numerical solution
========================

p9:physicalsoln(K_bn,C_Bn,sol,s):= block(
for i:1 thru 2 do(
if physicalm(sol,i) = true then s:subst([K_b=K_bn,C_B=C_Bn],sol[i])),
return(s));

numerical solution : before output symbolic equation , input the values , then 'return' 

 numerical :sol
----------------

example : values for weak base.

p9a:K_bn:10^(-5);

p9b:C_Bn:10^(-4);

p9c:OH = physicalsoln(K_bn,C_Bn,p6,s);

rem : use float

p9d:float(p9c);

Calculation : pOH, weak base
------------------------

p10:pOH(rhs(p9d)) ;

p10a:float(p10);

How to find : from equation 'p4e' for 'strong base'
=========================================
see: also part 3.

p11:p4e;

internet:
=======

Acid Strength and the Acid Dissociation Constant (Ka) = K_a
===================================================

https://chem.libretexts.org/Textbook_Maps/General_Chemistry
/Map%3A_A_Molecular_Approach_(Tro)/
16%3A_Acids_and_Bases/
16.04%3A_Acid_Strength_and_the_Acid_Dissociation_Constant_(Ka)

Table  16.4.2 : Values of  Kb ,  pKb ,  Ka , and  pKa  for Selected Weak Bases (B) and Their Conjugate Acids (BH+)

base  : B                                     K_b             , pK_b    
----------------------------------------------------------------------------------------
hydroxide ion : OH(-)              1                     , 0               => strong base
methylamine   : CH3NH2       4.6×10^(-4)    ,3.34         => weak base

rem : pK_b(1) = -log10(1) = 0

given : concentration,C_B = 0.01 M 
rem : removes memory :  C_B,K_b

p11a:p4f;

find OH: strong base, KOH ,see table 'above,strong electrolyt' ?
---------------------------------------

why :strong electrolyt , KOH     → K(+) + OH(-)
                                             NaOH  → Na(+) + OH(-)

quadratic equation:s1*x^2+s2*x+s3= 0 
----------------------------------------------------------

p11b:subst([OH=1,C_B = 0.01,K_b = 1 ],p11a);

solve quadratic equation
--------------------------------------

p11c:quadra2(p11b[1],p11b[2],p11b[3],aa);

find solution with physical meaning
------------------------------------------------------

p11d:OH = physicalsoln( 1,0.01,p11c,s);

relative value of term quadratic equation
-------------------------------------------------------------
use: p11a subst  p11d

p11e :subst([p11d,C_B = 0.01,K_b = 1],p11a);

look first term list much smaller, 'p11'
-----------------------------------------------

Equation strong base(with use p11a)
==================

p12:p11a[2]+p11a[3] =rhs(p11);

find OH :
-----------

p12a:solve(p12,OH);

find pOH : we only need concentration ' strong base'
------------

p12b:pOH(0.01);

p12c:float(p12b);

find pH : we only need concentration ' strong base'
------------
rem :pOH+pH = 14

p12d:14-p12c;

------------------------------------------------------------------------------------------------

people of chemistry : principal, quadratic equation
===========================================

relation between, weak acid and weak base
------------------------------------------------------------------

start : weak base , 'p11' , above.

quadratic equation : OH
------------------------------------

p13:p11;

how get weak acid , replace K_b => K_a
                                      replace C_B => C_HA
                                      replace OH   => H

p13a: [K_b = K_a,C_B = C_HA,OH   = H];

quadratic equation : H
------------------------------------

p13b: subst(p13a,p13);

relation between, strong acid and strong base
----------------------------------------------------------------------

strong base : OH^2  = 0  into  'p13'   => pOH
=============================

p14:K_b*OH-C_B*K_b=0;

 p14a:solve(p14,OH);

----------------------------------------------------------------------

rem : strong base ,only concentration solution .
           strong base => strong electrolyt

-----------------------------------------------------------------------

strong acid : H^2  = 0  into  'p13b'  => pH
=============================

p15:H*K_a-C_HA*K_a = 0;

p15a:solve(p15,H);

----------------------------------------------------------------------

rem : strong acid ,only concentration solution.
           strong acid  => strong electrolyt

-----------------------------------------------------------------------

relation : between pOH ,pH
=======================
=>    pOH + pH = 14
=>  def : pH = - log10(H), pOH = - log10(OH)

--------------------------------------------------------

rem : log use with base 10,  example :
log10(100) = 2  <=> 10^2 = 100

---------------------------------------------------------

-----------------------------------------------------------------------------------------