# -*- coding: utf-8 -*-
"""
Created on Sat Mar 21 17:54:28 2026

@author: KAPOTA
"""
#1- importation des bibliothèques
import matplotlib.pyplot as plt
#import scipy.optimize as op
import numpy as np

K1=10**7.6
K2=10**3.7
Kp=10**-5
Kc=10**-8.4
Ke=10**-14
pH_depart = 10
OH_depart = Ke/10**(-pH_depart)
Er = 10**-14
def Fonction(x):
    return 2*Kp/x**2 + Ke/x - 2*Kc*x**2/Kp - x*Kc/(K2*Kp) -x

def Derive(x):
    return -4*Kp/x**3 - Ke/x**2 - 4*x*Kc/Kp - Kc/(K2*Kp) -1

def newton (g , dg , Pt , Er ) :
    x = Pt
    while np.abs(g(x)) > Er :
        x = x - g (x ) / dg ( x ) 
    return x

OH_Sol=print('OH_sol=',newton(Fonction,Derive,OH_depart,Er),'mol/L')
