matlab code least square method
Afficher commentaires plus anciens
x = 7.38, 5.86, 2.46, 6.66, 0.83, 6.26, 6.61, 7.29, 8.91, 9.82
y = 11.89, 2.01, 4.54, 7.26, 1.61, 3.99, 7.16, 11.17, 10.44, 1.97
y(x) = c1x + c2x^(2/3) + c3xsin(x)
Hi all , how can I find optimal parameters for c1, c2, c3 by applying least square algorithm.
Réponses (1)
Image Analyst
le 15 Sep 2021
You forgot to attach your code. I know it's obvious, but did you try the usual, easy formula? When you tried it, what went wrong? You forgot to give your error message.
x = [7.38, 5.86, 2.46, 6.66, 0.83, 6.26, 6.61, 7.29, 8.91, 9.82]
y = [11.89, 2.01, 4.54, 7.26, 1.61, 3.99, 7.16, 11.17, 10.44, 1.97 ]
plot(x, y, 'b.', 'MarkerSize', 20);
grid on;
% y(x) = c1x + c2x^(2/3) + c3xsin(x)
A = [x(:), x(:).^(2/3), x(:) .* sin(x(:))]
% y = A * c, so c = y/A
c = y(:) \ A
xFit = linspace(0, 10, 500);
yFit = c(1) * xFit + c(2) .* xFit .^ (2/3) + c(3) * xFit .* sin(xFit)
hold on;
plot(xFit, yFit, 'r-', 'LineWidth', 2);

Catégories
En savoir plus sur Linear Algebra 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!