Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

I want to move the graph line by looping until finally it fits to the point as shown in the coding below. But not the line move from 1 to 5. And finally it gives you coefficient value. Plz hlp..

1 visualización (últimos 30 días)
function coeffs = optimalpolynomial(a,b)
xvalues =(0:a/4:a);
coeffs = zeros(1,5);
double(b);
double(a);
c=0;
y = (b-c).*rand(1,5) + c;
y_range = [min(y) max(y)];
plot (xvalues,y,'o',xvalues,coeffs,'r')
grid
xlabel('x-Werte')
ylabel('y-Werte')
title(['p(x) = ',num2str(coeffs(1,1)),'+',num2str(coeffs(1,2)),'*x+',num2str(coeffs(1,3)),'*x^2+',num2str(coeffs(1,4)),'*x^3+',num2str(coeffs(1,5)),'*x^4'])
for k=1:5
grid
pause;
plot (xvalues,y,'o');
grid
hold on;
plot (xvalues,[k k k k k],'r')
fprintf('new iteration!\n')
grid
hold off;
title(['p(x) = ',num2str(k),'+',num2str(k),'*x+',num2str(k),'*x^2+',num2str(k),'*x^3+',num2str(k),'*x^4'])
end
  1 comentario
Star Strider
Star Strider el 10 de Oct. de 2015
Be careful — coeffs is a Symbolic Math Toolbox function. If you have the Symbolic Math Toolbox, rename your function ‘mycoeffs’ (or something else), to avoid confusion.

Respuestas (1)

Eng. Fredius Magige
Eng. Fredius Magige el 11 de Oct. de 2015
Hi You are line could be moved vertically or horizontally through the proposed and targeted equation of:
title(['p(x) = ',num2str(k),'+',num2str(k),'*x+',num2str(k),'*x^2+',num2str(k),'*x^3+',num2str(k),'*x^4'])
polynomial equation p(x), means only affected/shifted by affecting x and NOT k as you think, might be (x-k).^ power (1,2,3 .....)

La pregunta está cerrada.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by