Saturday, March 24, 2012

7.17


When trying to find the acidity of a solution of magnesium hydroxide in hydrochloric acid, we obtain the following equation.

A(x) = x^3 + 3.5x^2 - 40

where x is the hydronium ion concentration. Find the hydronium ion concentration for a saturated solution (acidity equals zero) using two different methods in MATLAB.




x = [-2:.01:5];
A = [1 3.5  0 -40];
A2 = @(X) x .^3 + 3.5 * x .^2 - 40;


hold on
plot(x, polyval(A,[x]))
plot(x, A2(x),'r')
%plot(x, polyval(polyder(A),[x]),'r')




x_0 = 2;


k = polyder(A);
%Newton- Raphson method
for ii =1:23
     plot(x_0 ,polyval(A,x_0),'*g')
    x = x_0 - (polyval(A,x_0) ./ polyval(k,x_0));
    
    x_0 = x;  
end

hold off

The polyval function allows one to graph the polynomial and find the zero by simply evaluating it, and the newton-raphson method confirms the zero by converging to an x value of 2.5676, which when plugged into the equation gives us a value of zero


EDU>> x_0

x_0 =

    2.5676

EDU>> polyval(A,x_0)

ans =

     0

No comments:

Post a Comment