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.

 채택된 답변

Alan Stevens
Alan Stevens 2020년 11월 28일

2 개 추천

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)

댓글 수: 3

Car Ma
Car Ma 2020년 11월 28일
It worked! Thank you so much!
Image Analyst
Image Analyst 2020년 11월 28일
Then can you please "Accept this answer" to give Alan reputation points to thank him for helping you. You can also click the Vote icons to vote for answers and award them additional reputation points.
Car Ma
Car Ma 2020년 11월 28일
Done! thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 11월 28일

1 개 추천

Like it says, x must be a double, not a sym. f is a sym since x was (I'm guessing since I don't have the Symbolic Toolbox.) So just don't define a at all, and don't put polyfit() into sym() either.

댓글 수: 3

Car Ma
Car Ma 2020년 11월 28일
X is the parameter of the f function, and im using the f(x) function to get the values for the polyfit. Im trying to do the Lagrange polynome interpolator.
Thanks!
Image Analyst
Image Analyst 2020년 11월 28일
Fine, but do it numerically, not symbolically, like Alan and I told you.
Car Ma
Car Ma 2020년 11월 28일
Ok!

댓글을 달려면 로그인하십시오.

질문:

2020년 11월 28일

댓글:

2020년 11월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by