DON'T USE A HIGH ORDER POLYNOMIAL!
DON'T USE A HIGH ORDER POLYNOMIAL!
DON'T USE A HIGH ORDER POLYNOMIAL!
Do I need to say it again? I said it three times, so it must be true. High degree polynomials are a waste of computing power, and of your time. Yes, I know, you learned about Taylor series. What you have missed is many Taylor series are not convergent, and the only ones you get to play with as a student are the good ones.
What you did wrong I have not a clue. But it is trivial to fit a polynomial and then plot it.
x = rand(1,20);
y = sin(2*x) + randn(size(x))/10;
P3 = polyfit(x,y,3);
xpred = linspace(min(x),max(x),100);
ypred = polyval(P3,xpred);
plot(x,y,'bo',xpred,ypred,'r-')
Seems to work fine for me. Again, what you did wrong, we have no clue, because you don't tell us. If you really want help, then you need to show what you did.

