Group Abstract Group Abstract

Message Boards Message Boards

0
|
9.7K Views
|
43 Replies
|
12 Total Likes
View groups...
Share
Share this post:

How to set up a simple plot of pH against volume of titrant?

Posted 3 years ago
POSTED BY: Paul Newton
43 Replies
Posted 2 years ago
POSTED BY: Paul Newton
Posted 2 years ago

/. is ReplaceAll.

POSTED BY: Rohit Namjoshi
Posted 2 years ago
POSTED BY: Paul Newton
Posted 2 years ago

Another option is to use SolveValues, then ReplaceAll is not needed.

x = SolveValues[
  Rationalize[makeRelationEquation[Ka[pKa1], Kb[pKb], Ca1, Cb1, Va], 0], H]
x // Select[Positive] // First // N
POSTED BY: Rohit Namjoshi
Posted 2 years ago
POSTED BY: Paul Newton
Posted 2 years ago

Paul,

Please post complete working code. relationEquation2 refers to symbols Ca and Cb that are not defined anywhere earlier in this thread. Here is what I evaluated

Kw = 1.00*10^-14;
Ka[pKa_] := 10^-pKa;
Kb[pKb_] := 10^-pKb;
pKa1 := 4.757;
pKb := 0.63;
Ca1 := 0.1;
Cb1 := 0.1;
Va := 10;
Vb := 10;
relationEquation = 
  Vb == Va*((Ca/(1 + H/Ka)) - H + Kw/H)/((Cb/(1 + Kw/(H*Kb))) + H - Kw/H);
makeRelationEquation[Ka_, Kb_, Ca_, Cb_, Va_] = relationEquation;
x = Solve[Rationalize[makeRelationEquation[Ka[pKa1], Kb[pKb], Ca1, Cb1, Va], 0], H];

Extract the solutions, select the positive one and convert to a numerical value

H /. x // Select[Positive] // First // N
(* 2.06037*10^-9 *)

Exact value

H /. x // Select[Positive] // First // ToRadicals
(* Long expression *)
POSTED BY: Rohit Namjoshi
Posted 2 years ago
POSTED BY: Paul Newton
Posted 2 years ago

With exact input the result is also exact. In this case Root objects. Instead of the complicated nested Part you can do this

sol = H /. x

Which will return a list of the 4 solutions in sol. To get the numerical (inexact values)

sol // N

To get exact representations of the Root objects

sol // ToRadicals
POSTED BY: Rohit Namjoshi
Posted 2 years ago

Thank you, Rohit. Your suggestion looks as if it should be better and I have modified it thus:

x1A = Solve[
   Rationalize[makeRelationEquation2[Ka[pKa1], Kb[pKb], Ca1, Cb1, Va],
     0], H, Assumptions -> H > 0];

However the results of the two approaches are as shown (x1 is the original approach, x1A is your suggestion)

enter image description here

How would I get the numeric value from that last part?

POSTED BY: Paul Newton
Posted 2 years ago

It would be nice if I could somehow suppress that Solve: message

Use exact numerical values

x = Solve[Rationalize[makeRelationEquation[Ka[pKa1], Kb[pKb], Ca1, Cb1, Va], 0], H];

Use Quiet with caution. It will suppress all messages.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Quiet nice!

POSTED BY: Paul Newton
Posted 2 years ago

suppress that Solve: message

Wrap it your Solve[...] expression with Quiet. So Quiet[Solve[...]] or Solve[...]//Quiet

why, after making a change to the code, I have to Evaluate the notebook twice for the changes to be reflected?

I'm just guessing, but it probably has to do with all these symbols being global and therefore the sequence of computation is important.

So, for example if at the top of my notebook a evaluate a=7 and then later evaluate b=a, at that point we have "facts" that a is 7 and b is 7. Now if you evaluate a=13, you've only changed one of those facts, i.e. a is now 13 but b is still 7. If instead you had written b := a, then b would "pick up" the value of a each time it is evaluated.

But I haven't gone through your notebook recently, so that's just a guess.

POSTED BY: Eric Rimbey
Posted 2 years ago
POSTED BY: Paul Newton
Posted 2 years ago

Oh, sorry, I somehow was looking at a stale page. So, the criteria is simply positive. And you've already figured out how to use Assumptions. I think that's a good solution.

POSTED BY: Eric Rimbey
Posted 2 years ago

Probably, yes. Can you explain how you determine what a sensible value is? (I haven't gone back through this thread, so sorry if it's obvious.)

POSTED BY: Eric Rimbey
Posted 2 years ago
POSTED BY: Updating Name
Posted 2 years ago
POSTED BY: Paul Newton
Posted 2 years ago
POSTED BY: Paul Newton
Posted 2 years ago

Sure!

POSTED BY: Eric Rimbey
Posted 2 years ago

I don't know if you are still keeping an eye on this discussion, Eric, but if you are I thought you might be interested in what I have finally come up with. If you, or anybody else, is interested I will happily attach my notebook (such as it is).

POSTED BY: Paul Newton
Posted 3 years ago

I just realized that I didn't do anything around the table/columnar view, but I suspect you're pretty close on that part. Feel free to ask if there are still questions there.

POSTED BY: Eric Rimbey
Posted 3 years ago

That looks fantastic. At the moment I am working on getting data from a number of sources in order to compare and check results. This will take some time. Also, tomorrow I am taking delivery of a new computer and I'll need a few days to set it up and transfer stuff from my old computer.

All in all, I probably won't be able to look at this again until towards the end of next week. I hope that is OK with you and I really appreciate all the work you have put in so far.

POSTED BY: Paul Newton
Posted 3 years ago

POSTED BY: Eric Rimbey
Posted 3 years ago

If this is all true, - it is the truth, the whole truth and nothing but the truth

Yes, exactly, we can let the user manipulate Ka, Kb, Ca, Cb and Va

we want to show this in either orientation (i.e. for a target pH we want to see what Vb volume we need, or alternatively for a given Vb volume we want to know the pH we achieve

Yes again, but in both cases I would prefer pH on the y-axis

I had already sorted default values in Manipulate and that (and other things) are on the last notebook I attached and I did follow up on all the things you sent and referred to.

POSTED BY: Paul Newton
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago

Sorry for the confusion - "we don't need to know anything about Ka or Kb" applies in the laboratory situation when we are dealing with real solutions and glassware. Again, we are only solving for Ca in the laboratory.

So to clarify (and this will make more sense when you look at my latest version of the notebook which I have attached and to which I have added a number of enhancements)

Kw is always a constant 1.0 E-14

Ka, Kb are dependent on the acid and base respectively and will always be known

Ca, Cb are the concentrations of the acid and base respectively - and in the case of our Mathematica approach will be determined by the user

Va is the volume of acid to which we are adding the base - the user sets this value, usually to 5, 10, 20 or 25

What we are trying to achieve is a plot of pH vs Vb. We can do this in one of two ways;

The first way (which we have been working on) is to calculate Vb from pH. The resulting graph has Vb on the y-axis and pH on the x-axis - I don't know if the axes can be transposed, but it would be nice if they could

The second way (which is what we want to do next) is to calculate pH from Vb and then plot pH (y-axis) against Vb (x-axis). You said that you might find a way " I think we might be able to coerce Mathematica into solving the big hairy formula for pH." It might be a good idea to do this in a separate notebook.

I hope all this now makes sense but, if not, please let me know.

Attachments:
POSTED BY: Paul Newton
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago

That would be brilliant. There is absolutely no hurry -as it is, I'm going to be quite busy trying out your various suggestions. I thought you might like some background, so here goes:

Basically, this is an acid-base titration. We start off with a volume Va of an acid of "strength" Ka and (unknown) concentration Ca in a conical flask. Ka is a property of the acid in question. We can decide on what volume of acid Va we want to use. (typically 10, 20, or 25 cm3)

We then add from a burette incremental volumes Vb of the base of "strength" Kb. Kb is a property of the base, and we can decide on what (known) concentration of base Cb we want to use.

Experimentally, we don't need to know anything about Ka or Kb. For example, we place volume Va of acid of unknown concentration in the flask and then add the base of known concentration from the burette until the "end-point" is reached. Then note the volume of base Vb that was added to reach the end-point. From that, we can calculate the concentration of the acid in the flask.

POSTED BY: Paul Newton
Posted 3 years ago

Okay, sorry for the back-and-forth...

So, what we have is a relation between acid-volume and base-volume. It's expressed as acid-volume = base-volume * (some big hairy mess based on the other measurements/parameters). Is that correct?

And what you'd like is a formula that outputs pH based on the various acid/base measurements/parameters. Correct?

If my understanding is correct, then I think we might be able to coerce Mathematica into solving the big hairy formula for pH. But I'm heading out, away from my computer, for a bit. So, I can't set this up right now.

POSTED BY: Eric Rimbey
Posted 3 years ago

Vis-a-vis the divide by zero range error, it's a shame that instead of (for example) {Kb,0,1} which means 0 <= Kb <= 1 there could be way of stating the range as 0 < Kb <= 1

POSTED BY: Paul Newton
Posted 3 years ago

Sure. Sorry about the units (can't do superscripts here) Ca and Cb are the concentrations in mol dm-3 of an acid and a base Va and Vb are the volumes in cm3 of the acid and base Ka and Kb are the dissociation constants of the acid and base in mol dm-3 Kw is the ionic product of water in mol2 dm-6

The equation comes from an article in the journal School Science Review

Greatorex, D., 'Exact algorithms for acid/base titration curves', S.S.R. 1979, 214, 61, 94

I eventually got hold of a copy (attached) with help of a very kind ladyn at the Association for Science Education (the publishers of S.S.R.)

Attachments:
POSTED BY: Paul Newton
Posted 3 years ago

Can you tell me what each of the symbols is? Or provide a reference to the formula you’re using?

POSTED BY: Eric Rimbey
Posted 3 years ago

Many thanks, Eric. Best if I reply like you, referring to numbered sections/paragraphs

  1. That's now sorted, and something else I've learned

  2. Rewriting the equation would be a problem (at least for me). In Excel, I was able to use the equation as given (Vb = .....) and use GoalSeek. You have to specify an initial guess value, give it the value sought, and the cell to adjust in order to achieve that value. Might there be a way to do something similar with Mathematica?

3A I followed your instructions, and all is well, BUT when first run, there is a problem (see attached screenshot). This must be because one of the ranges starts at 0. Ideally, can we specify a range (say 0-5) and a default value (say 2.5)?

3B I will study the reference you provided and see whether it helps

4 That's what I wanted, and again will follow up on the reference

5 I'll start following up on your suggestions tomorrow, but I presume Table will now look something like

Table[{x, Vb[x, 0.1, 0.1, 4.76, 0.63, 1.*^-14, 10]}, {x, 3, 12.5, 0.2}]

Attachment

Attachments:
POSTED BY: Paul Newton
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago

4.

a choice of three or four pre-defined values

Yes. This is documented for Manipulate: http://reference.wolfram.com/language/ref/Manipulate.html

Specifically, you could use this form for (to take one example) Cb:

{Cb, {0.05, 0.1, 0.15}}

which will give you a setter bar with three choices.

POSTED BY: Eric Rimbey
Posted 3 years ago

3B.

...Also can the number of decimal places in the result be specified...

Look at the various *Form methods: http://reference.wolfram.com/language/guide/DisplayOfNumbers.html

Try NumberForm, for example.

POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago

2.

...what I really want to do is calculate pH for a range of values of Vb...

If you can rewrite the equation in terms of ph = <some complicated expression>, then sure, that's doable. I'm not going to try to do it myself :). Then we'll just write a definition like ph[<arguments go here>]:=<new definition goes here>.

POSTED BY: Eric Rimbey
Posted 3 years ago

1.

I would like to use pKa instead of Ka...

The expression

Ka[pKa_] := 10^-pKa

was evaluated after

Ka = 1.75 * 10^-5

and you can't set DownValues for a constant number. You can either clear definitions for Ka (e.g. ClearAll[Ka]) before your new definition, or just remove the first expression entirely if you're not going to depend on it as a constant anymore (although you'll still need to clear the symbol or restart the kernel because that definition will still be in Mathematica's "memory" even if you don't see it in the notebook anymore).

POSTED BY: Eric Rimbey
Posted 3 years ago
Attachment

Attachments:
POSTED BY: Paul Newton
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: Paul Newton
Posted 3 years ago
POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard