Wha'ts wrong with this?
2 次查看(过去 30 天)
显示 更早的评论
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))
Inputs must be floats, namely single or double.
0 个评论
采纳的回答
Alan Stevens
2020-11-28
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 个评论
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.
更多回答(1 个)
Image Analyst
2020-11-28
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!