-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileOperations.m
More file actions
executable file
·98 lines (92 loc) · 2.85 KB
/
Copy pathfileOperations.m
File metadata and controls
executable file
·98 lines (92 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function [methodName,time,mesg,answer,errors,rootsGauss,rootsJordan,rootsLU,rootsSeidel,errorsSeidel] = fileOperations (inputFilePath, outputFilePath)
if (strcmpi(outputFilePath,'null'))
outputFilePath = 'results of mult-equ.txt';
end
maxIterations = 50;
epsilon = 0.00001;
dataArray = importDataFromFile(inputFilePath);
methodName = dataArray.textdata(1);
fid = fopen(inputFilePath);
string(fgets(fid));
[coeffs, mesg] = getCoefficent(fgets(fid));
afterEqualSign = seperateComma(fgets(fid));
if (strcmpi(methodName,'gauss seidel') || strcmpi(methodName,'all'))
initalMatrix = seperateComma(fgets(fid));
maxIterationsCarry = str2double(fgets(fid));
epsilonCarry = str2double(fgets(fid));
end
fclose(fid);
if(~isempty(mesg))
return;
end
if(strcmpi(methodName,'gauss'))
now1 = tic();
[answer] = Gauss(coeffs,afterEqualSign);
time = toc(now1);
extraData = strcat('time:\t',string(time),' seconds');
errors=0;
rootsGauss=0;
rootsJordan=0;
rootsLU=0;
rootsSeidel=0;
errorsSeidel=0;
elseif (strcmpi(methodName,'gauss jordan'))
now1 = tic();
[answer] = Gauss_Jordan(coeffs,afterEqualSign);
time = toc(now1);
extraData = strcat('time:\t',string(time),' seconds');
errors=0;
rootsGauss=0;
rootsJordan=0;
rootsLU=0;
rootsSeidel=0;
errorsSeidel=0;
elseif (strcmpi(methodName,'LU decomposition'))
now1 = tic();
[answer] = LU_Decomposition(coeffs,afterEqualSign);
time = toc(now1);
extraData = strcat('time:\t',string(time),' seconds');
errors=0;
rootsGauss=0;
rootsJordan=0;
rootsLU=0;
rootsSeidel=0;
errorsSeidel=0;
elseif (strcmpi(methodName,'gauss seidel'))
if(maxIterationsCarry > 0)
maxIterations = maxIterationsCarry;
end
if (epsilonCarry > 0)
epsilon = epsilonCarry;
end
now1 = tic();
% function [ rootsMatrix,errors ] = GaussSeidel( coffMatrix,answerMatrix,initalMatrix,maxIterations,epsilon )
[ answer,errors ] = GaussSeidel( coeffs,afterEqualSign,initalMatrix,(maxIterations),(epsilon) );
time = toc(now1);
extraData = strcat('time:\t',string(time),'seconds','\nnumber of iterations:\t',string(size(answer,2)));
exportGaussSeidel(outputFilePath,answer,extraData,errors);
rootsGauss=0;
rootsJordan=0;
rootsLU=0;
rootsSeidel=0;
errorsSeidel=0;
return;
elseif (strcmpi(methodName,'all'))
if(maxIterationsCarry > 0)
maxIterations = maxIterationsCarry;
end
if (epsilonCarry > 0)
epsilon = epsilonCarry;
end
[rootsGauss,rootsJordan,rootsLU,rootsSeidel,errorsSeidel] = allMethodsMultiple ( coeffs,afterEqualSign,initalMatrix,maxIterations,epsilon );
errors=0;
answer=0;
time = 0;
return;
end
exportTableLinearEqu(outputFilePath,answer,extraData);
end
% while ischar(tline)
% disp(tline)
% tline = fgets(fid);
% end