How do I can build a MATLAB code to fit the following equation using least square sense ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad Adeeb
el 23 de Abr. de 2021
Comentada: Mohammad Adeeb
el 23 de Abr. de 2021
here is my equation : y=a+bx;
x=[1 2 3 4 5 6];
y=[3.5 0.5 -1.5 -3 -4.5 -7 ];
I've try this code
clc;
clear all;
close all;
%we need to do a line fitting to the following equation (y=a+bx)
X=[1; 2; 3; 4; 5; 6]; %
Y=[3.5; 0.5; -1.5; -3; -4.5; -7];
N=length(X);
AB=(X'.*X)*(X'.*Y); %coefficient matrix [a,b]
plot(X,Y,'o')
hold;
plot(AB(1:3,:),AB(4:6,:),'r-');
is that right? and what is the values of a,b
0 comentarios
Respuesta aceptada
Hiro Yoshino
el 23 de Abr. de 2021
The X dependes on how you want to fit your line to the data.
e.g., then X will be a series of stacked vertically upto the end of the data number.
11 comentarios
Hiro Yoshino
el 23 de Abr. de 2021
b = X\y
is the corresponding estimated coefficient vector.
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!