Question
Can't Figure Out why my Error is being displayed as above 5. It should only display a number less than 5 according to the while
Can't Figure Out why my Error is being displayed as above 5. It should only display a number less than 5 according to the while loop set up. Solving matrix using Gauss Seidel Method.
INPUT:
function GaussSeidel(a,b,lamda,es) %For 3X3 Matrix %02/25/20 William D. %GaussSeidel Method: Problem 11.8 a=[0.8,-0.4,0;-0.4,0.8,-0.4;0,-0.4,0.8]; b=[41;25;105]; lamda=1.2; %-> Correction Factor
es=5; n=length(b); %Find largest dimension of vector b iter=1; itermax=1000; %Max number iterations ea1=10; %initialize error values ea2=10; ea3=10; x1=0; %Initival guesses for x values x2=0; x3=0; while (es x1_old=x1; %replace new values calculated as old x2_old=x2; x3_old=x2; x1=(b(1)-a(1,2)*x2-a(1,3)*x3)/a(1,1); %Solve for new x1 value x1=lamda*x1+(1-lamda)*x1_old; %Correct x1 value, Enhances Convergence x2=(b(2)-a(2,1)*x1-a(2,3)*x3)/a(2,2); %Solve for new x2 value x2=lamda*x2+(1-lamda)*x2_old; x3=(b(3)-a(3,1)*x1-a(3,2)*x2)/a(3,3);%Solve for new x3 value x3=lamda*x3+(1-lamda)*x3_old; %Correct x3 value, enhance Convergence ea1=abs((x1-x1_old)*100/x1); %Find approx. errors ea2=abs((x2-x2_old)*100/x2); ea3=abs((x3-x3_old)*100/x3); iter=iter+1; %Increase Iteration Counter end fprintf('Error Values:') %Display Final Error Values disp(ea1) disp(ea2) disp(ea3) fprintf('X values') %Display Final X Values disp(x1) disp(x2) disp(x3) %Nobody Cares, Work Harder %Keep Hammering end
OUTPUT:
>> GaussSeidel Error Values: 9.8347
1.5494
3.1399
X values 180.6203
256.7983
261.0151
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started