41 lines
887 B
Matlab
41 lines
887 B
Matlab
function testSolve
|
|
result = Test([0, 1; 1, 1], [1; 1])
|
|
result = result & Test([11,44,1; 0.1,0.4,3; 0,1,-1], [1; 1; 1])
|
|
result = result & Test([0.001,1,1; -1,0.004,0.004; -1000,0.004,0.000004], [1; 1; 1])
|
|
|
|
if result(1) % nopivot
|
|
disp("Pivot-less Solving worked!")
|
|
else
|
|
disp("Pivot-less Solving broke!")
|
|
end
|
|
|
|
if result(2) % pivot
|
|
disp("Pivot-full Solving worked!")
|
|
else
|
|
disp("Pivot-full Solving broke!")
|
|
end
|
|
end
|
|
|
|
function [nopivot, pivot] = Test(A, b)
|
|
try
|
|
nopivot = isequal(Solve(A, b), linsolve(A, b))
|
|
catch
|
|
nopivot = false
|
|
end
|
|
|
|
try
|
|
pivot = isequal(SolvePivot(A, b), linsolve(A, b))
|
|
catch
|
|
pivot = false
|
|
end
|
|
end
|
|
|
|
function x = Solve(A, b)
|
|
x = solveLR(gaussLR(A), b)
|
|
end
|
|
|
|
function x = SolvePivot(A, b)
|
|
[A, T] = lrPivot(A)
|
|
x = solveLrPivot(A, T, b)
|
|
end
|