Iterative Method of solving multiple variables without using the curvefit tool
18 views (last 30 days)
Any form of help would be greatly appreciated. :)
I am a placement student and have used MATLAB (and various tools inside) quite extensively throughout my placements and degree. However my statistical knowledge of error methods is quite low and is hindering me completing this task. At the moment I am using an iterative method to try and curvefit a waveform from a test environment.
Iterative_waveform(I,:) = ((Vq1/xd)+(((Vq1/xDd)-(Vq1/xd))*exp(-t1/TDd))+(((Vq1/xDDd)-(Vq1/xDd))*exp(-t1/TDDd))).*sin(2*pi*f1*t1);
(This is the short current waveform of a synchrounous machine)
Vq1 = 556
t1 = known
xd = unknown
xDd = unknown
TDd = unknown
TDDd = unknown
xDDd = unknown
- The curvefit tool cannot curvefit the waveform even with the equation therefore I am trying to produce an iterative method to produce the correct variables
- Using an r^2 value on a sine wave is inaccurate, due to the fact that a perfect waveform could be out of phase from the original data. I can't find an error checking method for accrurately producing a error.
- does anyone know of a robust error checking method for a sinewave (was thinking of abs() then using r^2)
- does know how to converge using an error method for a sine wave due to the r^2 values increasing and decreasing through all iterations
David Wilson on 26 Jul 2019
Here's my attempt at fitting uusing lsqcurvefit from the optimisation toolbox.
First I generate some synthetic data to subsequently fit that follows your curve (since you didn't think to give us any)
Vq1 = 556; % known constant
N = 200; % # of points
t = linspace(0,0.2,N)';
f = 50; % presumably 50 Hz.
% Set values for constants
xd = 1;
xDd = 2;
TDd = 0.1;
TDDd = 0.05;
xDDd = 0.3;
phi = -0.6; % initial phase offset
y = (Vq1/xd+((Vq1/xDd-Vq1/xd))*exp(-t/TDd) + ...
Now we are ready to do the fitting:
%% Now use lsqcurvefit
p0 = 3*[1,1,1, 1, 1, 1]'; % guess of parameters
LB = [0,0,0, 0, 0, -5]'; % can put anything here, even -inf.
UB = 10*[1,1,1, 1, 1, 1]';
fun = @(p, t) (Vq1/p(1)+((Vq1/p(2)-Vq1/p(1)))*exp(-t/p(3)) + ...
pfit = lsqcurvefit(fun,p0,...
yfit = fun(pfit,t);
We get a pretty good fit since I start reasonably near the values used to generate the original curve.