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?

采纳的回答

Steven Lord
Steven Lord 2020-9-30
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by