% Known parameters
Rs = 40;           % R_s in Ohms
Rp = 10e9;         % R_p in Ohms
f = 100e3;         % frequency = 100 kHz
w = 2*pi*f;        
j = 1i;            % imaginary unit

% Suppose you have a measured impedance Z at 100 kHz:
% Replace this with your actual measured complex impedance value.
Z_measured = 1.5e6 + 0*j; % Example: purely real 1.5 MΩ

% Define A
A = (Rp*Rs)/(Rs + Rp);

% Use the derived formula:
% X = s*C_p = [ 1 - (Z - Rs)/Rp ] / [ (Z - Rs) - A ]
X = (1 - (Z_measured - Rs)/Rp) / ((Z_measured - Rs) - A);

% C_p = X / (j * w)
C_p = X / (j*w);

disp('Computed C_p (F):');
disp(C_p);
