From: Jonathan on 25 Feb 2010 11:06 Hi there, New Matlab user here. Trying to define a function that I want to try and fit my data to and I'm struggling to get it to work. Here's what I have: I have two 801x1 array, "Freq" and "data", the x and y data respectively. I want to try and fit to the equation: Y = K1 * 1 / (1 - K2*j*omega*tau), where omega = 2*pi*Freq, and tau is a constant I define explicitly in the code. K1 and K2 are coefficients that I want Matlab to compute. j = sqrt(-1). I have tried to define the fitting function using 'fittype' as follows: g = fittype('(K1/(1 - (1i*2*pi*K2*Freq*tau)))',... 'independent',{'Freq'},... 'coefficients',{'K1','K2'}); FittedData = fit(Freq,data,g); But I get an error message saying: "??? Error using ==> fittype.fittype>fittype.fittype at 477 Expression (C1/(1 - (1j*2*pi*C2*Freq*tau))) is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated: Error in fittype expression ==> (C1./(1 - (1j.*2.*pi.*C2.*Freq.*tau))) ??? Undefined function or variable 'tau'. Error in ==> Bandwidth_single at 101 g = fittype('(C1/(1 - (1j*2*pi*C2*Freq*tau)))',..." Which is where I'm totally lost. I don't really know what's gone wrong, or how to fix it. Any help would be appreciated.
|
Pages: 1 Prev: save integers in a text file Next: Fitting to a custom function |