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

1 view (last 30 days)
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

Answers (1)

Torsten
Torsten on 5 Aug 2024
Moved: Torsten on 5 Aug 2024
Indexing in MATLAB starts with 1, not with 0.

Categories

Find more on Data Types in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!