Gauss Seidel Method problem
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have to write two codes one for Jacobi and one for Gauss Schiedel
For the Gauss Schiedel one I coded
clc
clear
a=[1.2528,-1.4031,-2.45;0,3.3659,-0.2;1.6094,-3.8357,-5];
b=[-0.56,1.18,-6.37]';
x=[0,0,0]';
err=9000;
tol=0.01;
n=length(x);
while err>tol
x_1=x;
for i=1:n
sum=0;
for j=1:i-1
sum_1=sum+a(i,j)*x(j);
end
for j=i:n
sum_2=sum+a(i,j)*x_1(j);
end
x(i)=1/a(i,i)*(b(i)-(sum_1)-sum_2);
end
end
and in the error it says Unrecognized function or variable 'sum_1' for x(i)=1/a(i,i)*(b(i)-(sum_1)-sum_2); despite the fact that it is clearly stated before that there is a sum_1. Why is matlab not recognising the variable?
0 Kommentare
Antworten (1)
David Hill
am 29 Nov. 2019
sum_1 is not assigned before it is needed (for loop does not execute immediately). Recommend assigning sum_1 = 0 outside the while loop.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Function Creation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!