RE: How to find the point on the root locus with a certain damping in Octave
May 14, 2023 at 5:49 am
(This post was last modified: May 14, 2023 at 5:58 am by FlatAssembler.
Edit Reason: fixed a typo
)
OK, this C++ program I've made:
It prints out the following:
So, allegedly, for the gain of 0.723288, the damping is equal to 0.689481 (very close to the required damping of 0.7), and the frequency is 0.104 rad/sec. How do I check whether that's true?
Code:
#include <algorithm>
#include <complex>
#include <fstream>
#include <iostream>
#include <vector>
double prigusenje(std::complex<double> s) { return std::cos(std::arg(-s)); }
int main() {
using namespace std;
double potrebno_prigusenje = 0.7;
vector<complex<double>> nule{-0.003515, -1.754},
polovi{0, -20 * 1.754, -1.754, -0.1986, -0.003515};
vector<complex<double>> KMK;
vector<double> argumenti, prigusenja;
double epsilon = 0.001;
for (double x = -1; x < 1; x += epsilon)
for (double y = -4; y < 4; y += epsilon) {
complex<double> s(x, y);
complex<double> brojnik = 1, nazivnik = 1;
for (auto nula : nule)
brojnik *= s - nula;
for (auto pol : polovi)
nazivnik *= s - pol;
complex<double> Gs = brojnik / nazivnik;
if (abs(arg(Gs) * (180 / M_PI) - 180) < 3 * epsilon ||
abs(arg(Gs) * (180 / M_PI) + 180) < 3 * epsilon) {
KMK.push_back(s);
argumenti.push_back(arg(Gs) * (180 / M_PI));
prigusenja.push_back(prigusenje(s));
}
}
ofstream datoteka("KMK.txt");
datoteka << "x\ty\tphi\tdzeta\n";
for (int i = 0; i < KMK.size(); i++) {
complex<double> tocka = KMK[i];
double argument = argumenti[i];
double prigusenje = prigusenja[i];
datoteka << tocka.real() << '\t' << tocka.imag() << '\t' << argument << '\t'
<< prigusenje << '\n';
}
datoteka.close();
complex<double> najbolji = *min_element(
KMK.begin(), KMK.end(),
[potrebno_prigusenje](complex<double> prvi, complex<double> drugi) {
return abs(prigusenje(prvi) - potrebno_prigusenje) <
abs(prigusenje(drugi) - potrebno_prigusenje);
});
cout << "prigusenje = " << prigusenje(najbolji) << endl;
cout << "frekvencija = " << abs(najbolji.imag()) << endl;
cout << "x = " << najbolji.real() << endl;
double brojnik = 1, nazivnik = 1;
for (auto pol : polovi)
brojnik *= abs(najbolji - pol);
for (auto nula : nule)
nazivnik *= abs(najbolji - nula);
double pojacanje = brojnik / nazivnik;
cout << "pojacanje = " << pojacanje << endl;
}
Code:
prigusenje = 0.689481
frekvencija = 0.104
x = -0.099
pojacanje = 0.723288