0
votes

I have a complex function that I want to fit to some real data. The function is of the form:

Y = -2*imag((A-B)/(A+2*B)) ...................(1)

where

"imag" means imaginary part of the equation
A = a - (b/X)*1i .....................(2)
B = c - (d/X)*1i .....................(3)

Y has both imaginary and real parts. But it's the imaginary part that is relevant to my problem. How do I derive the values of a,b,c and d by fitting equation (1) to real experimental data? I have tried to use "lsqcurvefit" but it keeps returning the same starting values I put in! I am sure I must have missed something important.

Please kindly simplify your answers as much as possible as I'm still new at MATLAB.

Thanks.

1

1 Answers

1
votes

To run lsqcurvefit on your function, you can first create a file called f.m that contains:

function Y = f(params,X)

a = params(1);
b = params(2);
c = params(3);
d = params(4);

A = a - ((b ./ X) .* 1i);
B = c - ((d ./ X) .* 1i);

Y = 2 .* imag((A - B)./(A + 2*B));

Then call lsqcurvefit for this function and plot the results:

startParams = [1, 2, 3, 4];
x = 1:100;
y = f(startParams, x);
fitParams = lsqcurvefit(@f, startParams+1, x, y)

yFit = f(fitParams, x);
plot(x, y, 'b*')
hold on
plot(X, yFit, 'r')
legend('data','fit')