kill(all);

Maxima : intro computation ,base and acid, 'part :8a,version 1.0'
peter.vlasschaert@gmail.com, 04/12/2018

general :   6 ≤ ph=7 ≤ 8 : cubic equation
=================================

part 8:weak acid : ph just  'below ph = 7'
------------------------------------------------------------

  ================================

rem : part 9 :weak base : ph just  'above ph = 7'

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 :
===============

p1b: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 acid: HA
============

example : HAc , A=Ac,acetic acid (ned : azijnzuur)
pka = -log10(ka)

reaction : HA+H(2)O      ⇔ H(3)O(+) + A(-)         ....  '1'
reaction : H(2)O+H(2)O ⇔ H(3)O(+) + OH(-)      .... '1a'
----------------------------------------------------------------------------
rem:H(3)O(+) =H, A(-) = A,OH(-)=OH
----------------------------------------------------------------------------

equilibrium: take account both  '1' and '1a'.
----------------------------------------------------------------

Charge balance :
==============

----------------------------------------
 [H(3)O(+)]  = [A(-)] + [OH(-)] 
----------------------------------------

p1c:H = OH + A;

definition : pKa
============

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

definition : K_a       .... '2'
============

p2a:K_a = ((H)*(A))/(HA);

C_HA = concentration weak Acid  ... '3'
-------------------------------------------------

p3:C_HA=(HA)+(A);

How to find A from charge balance, 'p1c'
------------------------------------------------------------

1e)  solve for HA from 'p3'
======================

p4:solve(p3,HA);

2e)  put  HA into  'p2a'
======================

p4a:subst(p4,p2a);

3e)  solve for 'p4a'  for A
======================

p4b:solve(p4a,A)[1];

How to find OH from charge balance, 'p1c'
---------------------------------------------------------------

p4c: Kw = (OH)*(H);
p4d:solve(p4c,OH)[1];

Kw: see above.

insert 'p4b' and 'p4d' into 'p1c'
==========================

p5:subst([p4b,p4d],p1c);

p5a: rhs(p5)-lhs(p5)=0;

p5b:ratsimp(p5a);

result : above part p5b must be equal to zero

p6:part(lhs(p5b),1)=0;

p6a:expand(p6);

p6b:p6a*(-1);

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.1 : Values of  Ka ,  pKa ,  Kb , and  pKb  for Selected Acids ( HA  and Their Conjugate Bases ( A− )

acid  : HA                               K_a              , pK_a     
----------------------------------------------------------------------------------------
nitric   acid  :HNO3              2.3×10^1       ,−1.37       => strong acid
acetic acid  : CH3COOH   1.7×10^(-5)    ,4.76         => weak acid

given : concentration,C_HA = 0.01 M 
rem : removes memory :  C_HA,K_a

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

graphical representation :y= f(x) => pH=pH(-log10(C_HA))
--------------------------------------------------------------------------------------
=>  ' pH versus   -log10(C_HA) '
================================================

1e) Find C_HA  from 'p5' :
=====================

p7:solve(p5,C_HA);

p7a:factor(p7)[1];

p7b:H-part(rhs(p5),1);

p7c:rhs(p7a) = x*p7b;

p7d:solve(p7c,x)[1];

p7e:expand(p7d);

p7f:lhs(p7a) = subst([p7e],rhs(p7c));

p7g:rhs(p7f);

2e) graphics :
===========

How to display : x-axis
----------------------------------

=>       1,2,.....,7,....

p8:-log10(10^(-1));

p8a:-log10(10^(-2)),float,numer;

p8b:-log10(10^(-7)),float,numer;

concentration : function:C_HA = CA (.....)
-------------------------------------------------------------

We can take '' exact part . 
=====================

CA(H,K_a,Kw):=''p7g;

How to use : CA  = ' CH3COOH'
==========================

K_a = 1.74*10^(-5) , acetic acid 
Kw  = 10^(-14)        , dissociation constant water.

list :  information ,weak acid.
-------------------------------------------

p9:[K_a = 1.74*10^(-5),Kw  = 10^(-14)  ];

pH function from :
===============
PH = - log10[H(+)]   => [H(+)] = 10^(-pH)

p9a:H=10^(-pH);

find : pH =0
=========

p9a1:subst([pH=0],rhs(p9a));

p9b:CA(p9a1,p9[1],p9[2]);

find : C_HA; for pH = 2
===================

p9c:lhs(p7f)=rhs(p9b);

find : -log10(C_HA);  for pH=2
=========================

p9d:-log10(rhs(p9c)),numer,float;

list : pH : 0,1,2,3,...,10  => find  values -log10(C_HA)  for the list.
====================================================

syntax : ' makelist(function,index ,start,end)'
------------------------------------------------------------------

lista: makelist(i,i,0,10);

find H for CA(.......)
===============

listb:makelist(1/10^(pH),pH,0,length(lista)-1);

float(1/10000000000), numer;

find CA(...) for listd
================

principle :
=======

create empty list
-------------------------

listc:[];

how to put elements into empty list
-----------------------------------------------------

for i:1 thru  length(listb) do(
listc:endcons(i,listc));

length(listb);

listc;

start here:
========

listd:[];

for i:1 thru  length(listb) do(
listd:endcons(rhs(CA(listb[i],p9[1],p9[2])),listd));

listd;

length(listd);

-log10(C_HA) on listd
==================

pH = 0,first element.
-----------------------------

-log10(listd[1]),numer,float;

pH = 2,thrid element.
-------------------------------

-log10(listd[3]),numer,float;

pH = 3,fourth element.
---------------------------------

-log10(listd[4]),numer,float;

We want to remove: negative values from 'listd'
=======================================
why : we can't take : -log10() from C_HA
----------------------------------------------------------------------

liste:[];

for i:1 thru length(listd) do(
if is(listd[i]>0) =true then 
liste:endcons(listd[i],liste));

liste;

length(liste);

-log10() from C_HA
================

liste1:makelist(-log10(liste[i]),i,1,length(liste)),numer,float;

liste2:makelist(i,i,0,length(liste1)-1);

we want to plot  x: values , 'liste1'
                               y: values  ,'liste2'
============================

How to do this : manuel maxima :
============================

xy: [[10, .6], [20, .9], [30, 1.1], [40, 1.3], [50, 1.4]]$
 plot2d([[discrete, xy],l], [l,0,50],
        [style, points, lines], [color, red, blue],
        [point_type, asterisk],
        [legend, "experiment", "theory"],
        [xlabel, "pendulum's length (cm)"],
        [ylabel, "period (s)"])$

xy: [[10, .6], [20, .9], [30, 1.1], [40, 1.3], [50, 1.4]]$

wxplot2d([[discrete, xy],[discrete, xy]],
        [style, points, lines], [color, red, blue],
        [point_type, asterisk],
        [legend, "experiment", "theory"],
        [xlabel, "pendulum's length (cm)"],
        [ylabel, "period (s)"])$

We will make : xy from liste1,liste2
===============================
rem : xy , 'listf'

listf:[];

for i:1 thru length(liste1) do(
listf:endcons([liste1[i],liste2[i]],listf));

listf;

wxplot2d([[discrete, listf],[discrete, listf]],
        [style, points, lines], [color, red, blue],
        [point_type, asterisk],
        [legend, "weak acid", "weak acid"],
        [xlabel, "-log10(C_HA)"],
        [ylabel, "pH"])$