I'm guessing you've defined a variable named sum that's preventing you from calling the sum function. If my guess is correct clear the variable and recreate the anonymous functions.
Indexing errors on sum
1 次查看(过去 30 天)
显示 更早的评论
In = [38.68 7.84 5.14 3.92 3.14 2.62 2.22 1.78 1.74 1.55];
X = [1.4875 -0.4216 0.0390 -0.0008]
for c = 1:length(In)
Yf = @(In)sum(X(1:end).*In(c).^(0:Order));
Y(c) = Yf(c)
end
plot(In,Y)
This gives me the error Index exceeds the number of array elements (1).
the code is supposed to take the length of X(a list of coeficients) and plots the function
Y = X(1)*In.^(0) + X(2)*In.^(1) + X(3)*In.^(2) + X(4)*In.^(3)
So if the length of X is 5, then the function should be
Y = X(1)*In.^(0) + X(2)*In.^(1) + X(3)*In.^(2) + X(4)*In.^(3) + X(5)*In.^(4)
Am I doing this wrong? Is it possible to have matlab build the function itself like this?
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!