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

1 vue (au cours des 30 derniers jours)
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

Réponses (1)

Torsten
Torsten le 5 Août 2024
Déplacé(e) : Torsten le 5 Août 2024
Indexing in MATLAB starts with 1, not with 0.

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by