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