1
Maybe your question is how to adjust the points to a curve. If so you can use the polyfit function:
p = polyfit(x,y,n) returns the coefficients of the polynomial of degree n that best fits the data
Here is an example for an adjustment to a polynomial of degree 2
% gerando dados aleatorios para x e y
x = linspace(0,100,100)
y = x.^2+3*x+2
y = y + randn(size(y))*500
% aproximando os dados a um polinomio de grau 2
p = polyfit(x,y,2)
eq1 = strcat('y = ', num2str(p(1)),'x^2 + ',num2str(p(2)),'x + ',num2str(p(3)))
% mostra resultados na figura
figure(1)
hold on
plot (x,y,'+') % dados originais
text (max(x)/4,max(y)*5/6,eq1) % mostra a equacao no grafico
fitted_curve = p(1)*x.^2+p(2)*x+p(3) % cria curva ajustada para mostrar no grafico
plot (x,fitted_curve,'r') % mostra curva ajustada a vermelho no grafico
this Plot seems to me to be a vector isn’t it? what is the difficulty of adding and multiplying by the size of the vector ?? has some code ?
– ederwander