Skip to content
Browse files

removed a terrible, terrible array subscript error -.-

  • Loading branch information...
1 parent e9130f6 commit ad5b114d6775d061ebd9bf25c92cb991fa9d5ac9 @eagle2com committed Feb 22, 2012
View
5 LaplaceInverse/src/LinearSystem.cpp
@@ -20,10 +20,7 @@ inline const long double LinearSystem::Get(int n, int m)// line, column
return m_matrix[n*(m_size+1) + m];
}
-inline void LinearSystem::Set(int n, int m, long double value)
-{
- m_matrix[n*(m_size+1) + m] = value;
-}
+
void LinearSystem::SetNullCoefs(int m)
{
View
6 LaplaceInverse/src/LinearSystem.h
@@ -5,7 +5,11 @@ class LinearSystem
LinearSystem(int size); //only one dimension is required; we assume we have n variables and n equations
~LinearSystem(void);
inline const long double Get(int n, int m); // line, column
- inline void Set(int n, int m, long double value);
+ inline void Set(int n, int m, long double value)
+ {
+ m_matrix[n*(m_size+1) + m] = value;
+ }
+
void Add(int n, int m, long double value);
void Solve(void);
void Print(void);
View
8 LaplaceInverse/src/LiteralElement.cpp
@@ -93,7 +93,13 @@ void LiteralElement::Print(void)
else if(it->second->coef == 1)
sprintf(coef_buffer,"");
else
- sprintf(coef_buffer,"%1.0lf",it->second->coef);
+ sprintf(coef_buffer,"%1.0Lf",it->second->coef);
+
+ if(it->second->coef == 0)
+ {
+ sprintf(var_buffer,"");
+ sprintf(coef_buffer,"");
+ }
cout<<sign_buffer<<coef_buffer<<var_buffer<<exp_buffer;
}
View
2 LaplaceInverse/src/Makefile
@@ -1,3 +1,3 @@
all:
- g++ Literal.cpp LiteralElement.cpp LinearSystem.cpp TransferFunction.cpp main.cpp
+ g++ *.cpp
View
8 LaplaceInverse/src/TransferFunction.cpp
@@ -106,10 +106,10 @@ void TransferFunction::PrintFactors(void)
cout << "[ ";
for(int i = 0; i < denominator.size()*2-1; i++)
{
- cout << correct_factors[i] << " | ";
+ cout << factors[i] << " | ";
}
- cout << correct_factors[denominator.size()*2-1]<<" ]";
+ cout << factors[denominator.size()*2-1]<<" ]";
}
void TransferFunction::NicePrintFactors(void)
@@ -167,8 +167,10 @@ void TransferFunction::FindFactors(void)
{
if(i == current_factor) // we want to exclude the current factor, obviously
continue;
- elems[i] = elems[i]->Multiply(denominator[i]);
+ denominator[i]->Print();
+ elems[current_factor] = elems[current_factor]->Multiply(denominator[i]);
}
+ cout << " = ";elems[current_factor]->Print();cout << endl;
}
Literal* temp = NULL;
View
21 LaplaceInverse/src/main.cpp
@@ -13,10 +13,27 @@ TransferMap functions;
int main(int argc, char **argv)
{
+ int choice;
TransferFunction f1;
- f1.LoadFromFile("test.txt");
+ cout << "Interactive or from file(0,1): ";
+ cin >> choice;
+ if(choice == 1)
+ {
+ string filename;
+ cout << "File to load:";
+ cin >> filename;
+ f1.LoadFromFile(filename);
+ }
+ else if(choice == 0)
+ f1.Interactive();
+ else
+ {
+ cout << "Unkown choice, exiting."<<endl;
+ exit(0);
+ }
f1.FindFactors();
+
cout << "Factors: "; f1.PrintFactors(); cout << endl;
return 0;
-}
+}
View
1 LaplaceInverse/src/test2
@@ -0,0 +1 @@
+1 1 1 2 3 1 1 -1 2 1 0 3 2 1 0 -6

0 comments on commit ad5b114

Please sign in to comment.
Something went wrong with that request. Please try again.