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 日間)
athif amran
athif amran 2015 年 10 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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