Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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 visualizzazione (ultimi 30 giorni)
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 Commento
Star Strider
Star Strider il 10 Ott 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.

Risposte (1)

Eng. Fredius Magige
Eng. Fredius Magige il 11 Ott 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 .....)

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by