Java Security Settings:
      This web page employs Java, which requires specific security settings for correct operation.
      If the applets on this page do not run correctly, consult the Virtual Chemistry Experiments FAQ
      or the Physlet Physics web site for establishing the correct security settings.

Demonstration of the ChemEquilibria Applet

Most of the features of the chemEquilibria applet are controlled by Javascript commands, which are described in the documentation. This page provides examples of some of the features of the applet.

Curve-Fitting a Titration Curve - Part 1

This page illustrates the use of the Equilibria package and the ChemEquilibria applet in solving equilibrium problems.

Step 1. Preliminary Analysis of the Experimental Data

The titration curve shown below was obtained for the titration of 100.0 mL of 0.003909 mole/L HClO4 by an ethylenediamine (en) solution.

The ChemEquilibria applet can assist in the analysis of this data. Ultimately one desires to curve-fit the experimental data in order to obtain the best values for pKa1 and pKa2 for H2en+2 and the molar concentration of ethylenediamine in the titrant.

In preparation for the curve-fitting procedure, it is necessary to perform a preliminary analysis to obtain good initial guesses for pKa1, pKa2, and Cen. A common technique for locating the equivalence points is to plot the first and second derivatives of the titration curve. The Titration object provides this analysis.

At this point it is not necessary to define the chemical system. One need simply create the Titration object and supply the experimental data. Dummy values are provided for the titrant and sample solution.

document.chemEquilibria.createTitration(" "," ");

Although the Titration object has a method for accepting an array of data points, some browsers (e.g., Internet Explorer 5.0) do not support this functionality. Consequently points are supplied as individual pairs. For example, the first data point is Vt = 0.00 mL and pH = 2.46. This point can be added using the following JavaScript instruction. (Unlike other methods, the Titration object accepts volumes in mL for titration curve data.) The experimental data must be provided in order of increasing titrant volume.


Once the data has been provided, the getDerivative and getDerivative2 methods can be used to obtain the first and second derivatives of the experimental data. As before, the inability of some browsers to accept arrays from Java methods requires that the individual points be obtained one at a time. The instructions below retrieve the first and second derivatives at the 5th point.

first_derivative = document.chemEquilibria.getDerivative(5);
second_derivative = document.chemEquilibria.getDerivative2(5);

The derivative plot clearly reveals the location of the two equivalence points (points at which the slope is a maximum). The second equivalence point occurs at exactly twice the volume of the first equivalence point, which is easier to detect. The first equivalence point occurs at 10.865 mL of titrant, indicating the concentration of the ethylenediamine is 0.01799 mole/L. Bear in mind that the en is doubly protonated at the first equivalence point. The position of the maximum in the first-derivative plot can be easily determined by placing the cursor over the maximum position and pressing the left mouse button to display the cursor position.

This same information can be obtained from the second derivative plot (red points). The first equivalence point is easy to detect on this plot, because the second derivative is quite large just before and just after the equivalence point. The inflection at the second equivalence point is much smaller. The blue points display the second derivative multiplied by a factor of 200, and with this expanded view the inflection at the second equivalence point is also easy to see.

If the titrant concentration can be determined with sufficient accuracy at this stage, it is not necessary to include this value in the curve-fitting procedure. Although this value for the concentration of en is sufficiently accurate, it will nonetheless be optimized in the curve-fitting in order to demonstrate the curve-fitting capabilities of the equilibria software.

It is also necessary to estimate pKa1 and pKa2. At the first equivalence point, the solution contains predominantly H2en+2. At the second equivalence point, the solution contains predominantly Hen+. Half-way between these two points, at Vt = 16.3 mL, the solution contains approximately equal amounts of H2en+2 and Hen+ and the pH is approximately equal to pKa1. Using the plot of the titration curve, one estimates pKa1 = 7.19. (Because pKa1 and pKa2 are fairly close in value, there is substantial disproportionation of Hen+ and one does not expect the pH at this mid-point to exactly coincide with pKa1. But this approximate value should be an acceptable seed value for the curve-fitting.)

At the second equivalence point (Vt = 21.7 mL), the solution contains predominantly Hen+. After another 21.7 mL of titrant is added (total Vt = 43.4 mL), the solution contains equal amounts of Hen+ and en and the pH is approximately equal to pKa2. Using the plot of the titration curve, one estimates pKa2 = 9.80.

Step 2. Define the Chemical System

The chemical system contains two phases: the titrant (t) and the sample solution (aq). The titration involved 100.0 mL of sample solution and about 50 mL of titrant. The following JavaScript instructions create 100.0 mL of each solution. The volume of the sample solution is the volume that will be titrated. The volume of titrant need only exceed the maximum value of titrant to be added during the titration.


The various chemical species in the system must be defined and added to the chemical system.

document.chemEquilibria.addAcidBaseSpecies("en", 0.0, 60.10, 2, "t", 0.0);

The addAcidBaseSpecies method creates and adds en, Hen+, and H2en+2. In this case the species are "added" to the titrant, but in an analytical amount of zero. The addSpecies method is used to add 0.100 L (0.01799 mole/L) = 0.001799 mole of en to the titrant.

The only reactions that need to be defined are the acid-base reactions of ethylenediamine. Recall that the software automatically defines the autodissociation reactions and the conjugate acid and base of the solvent.

document.chemEquilibria.addReaction("Ka1","H2en+2 (t) = Hen+ (t) + H+ (t)", 6.46E-8);
document.chemEquilibria.addReaction("Ka2","Hen+ (t) = en (t) + H+ (t)", 1.58E-10);

The Ka values are the best-estimates determined above. These values will serve as seed values for the curve-fitting procedure.

It is only necessary to define the acid-base reactions for the titrant, because initially the reactions only occur in the titrant. During the course of calculating the titration curve, the transferSolution method is used. This method not only transfers species from one solution to another (titrant to sample solution in this case) but also ensures that homogeneous reactions for the titrant are also defined for the sample solution.

For the purposes of this demonstration, ideal behavior will be assumed. The titration object must also be created (to establish the correct titrant and sample solution), and it is necessary to establish that the titration data consists of the pH of the sample solution.


Step 3. Perform the Curve-Fitting Procedure

It is necessary to specify the uncertainty (the standard deviation) of the experimental data. The error is assumed to exist entirely in the pH values, and such values are usually not reliable to better than 0.03 (which is the default standard deviation). In this case it is assumed that all values have the same standard deviation. It is possible to define an unique standard deviation for each point, but this option will not be employed here. If a constant standard deviation is used, it must be defined before the experimental data is added.


Because a new titration object was created, the experimental data must be provided to the new titration object using the addDatum method (as above). All of the experimental data will be used in the curve-fitting procedure.

Note:One must exercise good judgement in deciding which experimental data to include in the curve-fitting procedure and which to omit. The basic rule of thumb is to omit any data that is approximately independent of the parameters being optimized. In this case, for example, data for Vt < 9 mL should be excluded from the curve-fitting, because the pH values in this region are essentially independent of Ka1, Ka2, and Cen. Under the best of circumstance, the inclusion of such data would have no impact upon the results of the curve-fitting. Under the worst of circumstances, especially if there is poor agreement between theory and experiment in this region, the curve-fitting process would be dominated by a futile attempt to fit data that is independent of the parameters being optimized. A second important guideline is to omit any points possessing unusually large error (i.e., outliers), because it is possible for a few points possessing serious experimental error to seriously corrupt the curve-fitting process. Fortunately no such points exists in this data set.

One must also specify which parameters are to be varied to obtain a good fit. Two possibilities exist. If a reaction is specified, the equilibrium constant (actually ln K) is varied to obtain a good fit. If a species is specified, the analytical concentration (actually ln n, where n is the analytical number of moles) of the species is varied. Both types of parameters are defined using the addPar method. The first argument is 'R' for a reaction or 'S' for a species. The second parameter is the identifying label for the reaction or species. In the case of a species, the third argument identifies the phase. For a reaction, a dummy third argument is provided.

In this case we wish to optimize pKa1, pKa2, and Cen.

document.chemEquilibria.addPar("R","Ka1"," ");
document.chemEquilibria.addPar("R","Ka2"," ");

The curve-fitting is initiated by the fit method. If this method returns true, the fitting was successful. A false value indicates that one or more error was encountered and the Java console should be examined for error messages.

By default the fit method performs a maximum of 100 iterations. If convergence has not been achieved by that point, the method aborts. Depending upon the nature of the problem, the fitting procedure, which implements the Levenberg-Marquardt algorithm, may be slow to converge, especially if the seed values are far from the optimal values. If this problem occurs (and it should not in this case), one may use the setDisplayFitIterations to view the parameters at each iteration during the curve-fitting process. This information may suggest better seed values. In addition one may wish to discard experimental data that does not distinguish between the various parameters. This is one of the challenging features of curve-fitting efforts: The system may be simultaneously over-determined and under-determined. The system is over-determined in the sense that there are more (frequently many more) observations than adjustable parameters. The system may be under-determined in the sense that different parameter values may produce fits of comparable quality.

var state =;

The results of the curve-fitting process are retrieved using the getPar and getParStd methods. These methods require as arguments the index of the parameter. Parameters are numbered beginning with zero in the order defined. (Bear in mind that the curve-fitting actually produces the moles of ethylenediamine in the original 100.0 mL of titrant rather than Cen itself.)

var pKa1 = -Math.log(document.chemEquilibria.getPar(0))/Math.log(10.0);
var pKa2 = -Math.log(document.chemEquilibria.getPar(1))/Math.log(10.0);
var pKa1_std = document.chemEquilibria.getParStd(0)/(document.chemEquilibria.getPar(0)*Math.log(10.0));
var pKa1_std = document.chemEquilibria.getParStd(1)/(document.chemEquilibria.getPar(1)*Math.log(10.0));
var Cen = document.chemEquilibria.getPar(2)/0.100;
var Cen_std = document.chemEquilibria.getParStd(2)/0.100;
var gof = document.chemEquilibria.getGoodnessOfFit();
Parameter Best-Fit Value Standard Deviation

The goodness-of-fit provides a useful assessment of the quality of the fit. A quality fit should produce a goodness-of-fit near unity. An unusually large goodness-of-fit indicates that the theoretical curve does not fit the data as well as the precision of the data suggests it should. This may indicate an inappropriate model or that the standard deviation of the data has been under-estimated. A goodness-of-fit significantly below unity indicates that fit is better than one would expect based upon the precisions of the data, suggesting that the standard deviation of the data has been over-estimated ... or that the data has been fudged.

The number of degrees of freedom is f, which is the number of data points minus the number of parameters fit to the data. For a large value of f, the goodness-of-fit is normally distributed about unity with a standard deviation of (2/f)1/2. In this case f = 44-3 = 41 and the standard deviation of the goodness-of-fit is 0.22. One would expect the goodness-of-fit to lie within about two standard deviations of unity, which would be the range 0.6 to 1.4.

Step 4. Compare Theory and Experiment

Having performed the curve-fitting, it is now necessary to compare the best-fit titration curve produced by the curve-fitting with the experimental data in order to evaluate the quality of the fit. At no point in the entire curve-fitting process has the original chemical system been altered. Consequently the values of Ka1, Ka2, and Cen remain the original seed values defined above. The apply method may be employed to update all equilibrium constants and analytical concentrations (actually analytical number of moles) to the best-fit values produced by the fit method.


The calculate method calculates a titration curve for Vt = 0 mL to the specified volume (in mL) and automatically determines how much titrant to add at each step in the titration in order to obtain a smooth curve with well-defined equivalence points.


The experimental points are shown as red dots and the theoretical curve is shown as a solid blue line.

Curve-Fitting a Titration Curve - Part 2

CurveFit1.html version 2.1
© 2001-2014 David N. Blauch