Skip to content

Commit 906f6da

Browse files
author
mmiranda96
committed
Fixed codes
1 parent 7096781 commit 906f6da

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

src/matrices/cramer.sci

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
function [R] = cramer(A, B)
2-
s = size(A);
3-
detS = det(A);
4-
R = zeros(s(1), 1);
5-
for i = 1 : s(1)
6-
t = A(:, i);
7-
A(:, i) = B;
8-
R(i) = det(A) / detS;
9-
A(:, i) = t;
10-
end
11-
endfunction
12-
13-
A = [3., -0.1, -0.2; 0.1, 7., -0.3; 0.3, -0.2, 10.]
14-
B = [7.85; -19.3; 71.4]
15-
16-
R = cramer(A, B)
1+
function [R] = cramer(A, B)
2+
s = size(A);
3+
detS = det(A);
4+
R = zeros(s(1), 1);
5+
for i = 1 : s(1)
6+
t = A(:, i);
7+
A(:, i) = B;
8+
R(i) = det(A) / detS;
9+
A(:, i) = t;
10+
end
11+
endfunction
12+
13+
A = [1., 2.; 1., -2.]
14+
B = [9.; 1.]
15+
S = cramer(A, B)

src/root_finder/bairstow.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <iostream>
22
#include <cmath>
33
#include <vector>
4+
#include <stdlib.h>
45

56
using namespace std;
67

@@ -135,7 +136,15 @@ void bairstow(vector<double> &pol, vector<complex*> &roots, double pi, double qi
135136
}
136137

137138
int main(int argc, char* argv[]) {
138-
vector<double> pol = {1, -3, 2.2, 1.22, -0.02, 189};
139+
if (argc < 3) {
140+
cerr << "This method receives a polynomial of minimum grade = 2, expressed from more significant coefficient to less significant." << endl;
141+
return -1;
142+
}
143+
vector<double> pol(argc - 1, 0);
144+
cout << pol.size() << endl;
145+
for (int i = 1; i < argc; i++) {
146+
pol[i - 1] = atof(argv[i]);
147+
}
139148
vector<complex*> roots;
140149
double p = -1;
141150
double q = -1;

src/root_finder/secant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using namespace std;
66

77
double f(double x) {
8-
double fx = log(abs(x)); //Something
8+
double fx = pow(x, 3) + 10 * x + 5; //Something
99
if (isnan(fx)) {
1010
cerr << "Function is discontinuous on " << x << endl;
1111
}

0 commit comments

Comments
 (0)