Last active
April 23, 2021 19:39
-
-
Save lecuseasar/ceae5ffb398cae3709ec923cb41634c8 to your computer and use it in GitHub Desktop.
my matlab homework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clc; clear; close all; format('long', 'g'); | |
fprintf("Gauss Seidel\n3x-0.1y-0.2z = 7.85 AND\n 0.1x+7y-0.3z = -19.3 AND\n 0.3x-0.2y+10z = 71.4 AND\n if error_x < 0.01 break; \n\n"); | |
index = 1; | |
x(index) = 0; | |
y(index) = 0; | |
z(index) = 0; | |
error_x = 9999; | |
while error_x(index) >= 0.01 | |
x(index + 1) = (7.85 + 0.1 * y(index) + 0.2 * z(index)) / 3; | |
y(index + 1) = (-19.3 - 0.1 * x(index + 1) + 0.3 * z(index)) / 7; | |
z(index + 1) = (71.4 - 0.3 * x(index + 1) + 0.2 * y(index + 1)) / 10; | |
error_x(index + 1) = abs(x(index + 1) - x(index)) / x(index + 1) * 100; | |
error_y(index + 1) = abs(y(index + 1) - y(index)) / y(index + 1) * 100; | |
error_z(index + 1) = abs(z(index + 1) - z(index)) / z(index + 1) * 100; | |
index = index + 1; | |
end | |
disp(' x error(%)'); | |
disp([x', error_x']); | |
disp(' y error(%)'); | |
disp([y', error_y']); | |
disp(' z error(%)'); | |
disp([z', error_z']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment