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

1 次查看(过去 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
移动:Torsten 2024-8-5
Indexing in MATLAB starts with 1, not with 0.

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by