## Contents

clc
clear all

## Load frequency, experiment data and initial guess values

freq = importdata('D:/EIS_sim/freq.txt');
Impedance_exp = importdata('D:/EIS_sim/test.txt');
parameter = importdata('D:/EIS_sim/parameter.txt');
Re_exp = Impedance_exp(:,1);
Im_exp = Impedance_exp(:,2);
Z_exp(1,:) = Re_exp;
Z_exp(2,:) = Im_exp;

## Fitting Implementation

lb = [0.999 0 0 0 0 0 0 0 0 0];
ub = [1.001 inf inf inf inf 1 inf inf 1 inf];
[final_fit,resnorm,residual,exitflag,output] = lsqcurvefit(@model, parameter, freq, Z_exp, lb, ub);
Z = model(final_fit, freq);
Re = Z(1,:);
Im = Z(2,:);

Local minimum possible.
lsqcurvefit stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.

## Plot the data

plot(Re, Im, Re_exp, Im_exp, 'o');
legend('Simulation','Experiment');
xlabel(' Real / Ohm');
ylabel(' Imagine / Ohm')