MATLAB: Wha’ts wrong with this

anonymous functiondon't use symSymbolic Math Toolbox

I'm very new and I can't detect what's wrong here. I would be very pleased if you could help me. Thanks!
syms x
f(x)=sin(x+1)*sqrt(x+1)
sym(polyfit([1,2,3,4],[f(1),f(2),f(3),f(4)],3))
Error using polyfit
Inputs must be floats, namely single or double.

Best Answer

Try
f = @(x) sin(x+1)*sqrt(x+1);
p = polyfit([1,2,3,4],[f(1),f(2),f(3),f(4)],3);
x = 1:0.01:4;
y = polyval(p,x);
plot([1,2,3,4],[f(1),f(2),f(3),f(4)],'o',x,y)
Related Question