Professional Documents
Culture Documents
Examen Lenguaje de Programacion - CFD - Jesus Cruz Contreras
Examen Lenguaje de Programacion - CFD - Jesus Cruz Contreras
Examen Lenguaje de Programacion - CFD - Jesus Cruz Contreras
% A: Coefficient matrix
D = diag(diag(A));
R = A - D;
x = x0;
iterations = 0;
for k = 1:max_iterations
x_old = x;
x = D \ (b - R * x_old);
% Check for convergence
iterations = k;
return;
end
end
error('Jacobi method did not converge within the maximum number of iterations');
end
% Coefficient matrix
A = [1, 1, 1, 1;
2, 3, 1, 2;
1, 2, 3, 1;
3, 1, 2, 4];
% Initial guess
x0 = [0; 0; 0; 0];
% Tolerance
tolerance = 1e-5;
max_iterations = 1000;
disp('Solution:');
disp(x);
disp('Iterations:');
disp(iterations);
% A: Coefficient matrix
n = length(b);
x = x0;
iterations = 0;
for k = 1:max_iterations
x_old = x;
for i = 1:n
sum1 = 0;
for j = 1:i-1
end
for j = i+1:n
end
end
iterations = k;
return;
end
end
error('Gauss-Seidel method did not converge within the maximum number of iterations');
end
% Coefficient matrix
A = [1, 1, 1, 1;
2, 3, 1, 2;
1, 2, 3, 1;
3, 1, 2, 4];
% Right-hand side vector
% Initial guess
x0 = [0; 0; 0; 0];
% Tolerance
tolerance = 1e-5;
max_iterations = 1000;
disp('Solution:');
disp(x);
disp('Iterations:');
disp(iterations);
end
MÉTODO SOR
% A: Coefficient matrix
n = length(b);
x = x0;
iterations = 0;
for k = 1:max_iterations
x_old = x;
for i = 1:n
sum1 = 0;
for j = 1:i-1
end
for j = i+1:n
end
end
iterations = k;
return;
end
end
error('SOR method did not converge within the maximum number of iterations');
end
% Coefficient matrix
A = [1, 1, 1, 1;
2, 3, 1, 2;
1, 2, 3, 1;
3, 1, 2, 4];
% Initial guess
x0 = [0; 0; 0; 0];
% Tolerance
tolerance = 1e-5;
max_iterations = 1000;
% Relaxation factors
disp(x);
end
Triangle.h
#ifndef TRIANGLE_H
#define TRIANGLE_H
class Triangle {
private:
public:
// Constructor
Triangle(double x1, double y1, double x2, double y2, double x3, double y3);
};
#endif // TRIANGLE_H
Triangle.cpp
#include "Triangle.h"
#include <cmath>
// Constructor
Triangle::Triangle(double x1, double y1, double x2, double y2, double x3, double y3)