Info

此问题已关闭。 请重新打开它进行编辑或回答。

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 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2015-10-10
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.

回答(1 个)

Eng. Fredius Magige
Eng. Fredius Magige 2015-10-11
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 .....)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by