I'm getting following error: Array indices must be positive integers or logical values.

16 次查看(过去 30 天)
Hi, when I test following code whit some easy nubers I get the error: Array indices must be positive integers or logical values. (in the line I(0) = b - a) I already tried clearing the workspace but the same error keeps popping up. What else could be the problem?
function [H] = ComputeWeights(a,b,x)
n = length(x)-1;
I = ones(n+1);
I(0) = b - a;
I(1) = 0;
for i = 2:n+1
I(i) = ((b-a)*((-1)^i + 1))/(2*(1-i^2));
end
for i = 0:n+1
x(i) = ((2/(b-a))*(x-a))-1;
end
T = zeros(n+1,n+1);
for i = 0:n+1
for k = 0:n+1
T(i,k) = cos(k*acos(x(i)));
end
end
H = linsolve(T,transpose(I));
end

回答(1 个)

Torsten
Torsten 2024-8-5,13:05
移动:Torsten 2024-8-5,13:06
Indexing in MATLAB starts with 1, not with 0.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by