Using least square fitting function lsqr
Afficher commentaires plus anciens
Hello,
I need an example how to apply Matlab's built in lsqr function to solve the following task.
let's say I have a sequence of square pulses which is transformed in the following way:
rng(0)
n = 20;
s = rand(1, n) > 0.5;
s = repmat(s', 1, 100)';
s = s(:)';
t = linspace(0, n, numel(s));
subplot(2, 1, 1)
plot(t, s, 'Linewidth',2)
scale_factor = 1.05;
offset = 1.5;
t2 = t * scale_factor + offset;
subplot(2, 1, 2)
plot(t2, s, 'LineWidth',2)
Now if that previous transformation is unknown and I need to estimate scale_factor and offset i.e. my initial condition is actually only a plot data:

or my only inputs are:
t1_n = t(s==1);
T1 = [t1_n; ones(size(t1_n))];
t2_n = t2(s==1);
T2 = [t2_n; ones(size(t2_n))];
How to use lsqr function to calculate scale_factor and offset. I know that for this particular case, I only need to points to calculate coefficients of line equation y = a*x+b, but in general, data can be noisy, so more points are needed and thus the obvious choise would be to use least square fitting.
Thank you!
P.S. I forgot to mention, I can solve this problem using the function lsqcurvefit, but I would like to see how lsqr can be applied.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics and Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
