Abstract:
This standalone application plots the reponces of second order series and parallel RLC circuits, which makes easier to tune RLC applications.
In this project you can set the frequencies of the different circuits which are used in transmission or any other circuits.
Code for Second Order RLC Circuit Response:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <complex>
#include <QPixmap>
#include <algorithm>
#include <QImage>
#define pi 3.1416
double S_V_s,S_I_o,S_V_o,S_R,S_L,S_C,w0_2,w0,alpha,err,di,dv;
double s_1,s_2,A_1,A_2,A_1_i,A_2_i,t_f,t=0.0,s_i,si_L,svc_L,svr_L,pir_C,pil_C;
double P_I_s,P_I_o,P_V_o,P_R,P_L,P_C,L,C,R;
QVector<double>vect_s_i,vect_t,vect_s_c,vect_s_r,vect_s_l,vect_p_v,vect_p_i_l,vect_p_i_r,vect_p_i_c;
//defination of i
std::complex<double>j(0,1),c_s_1,c_s_2,w_d(0,0),A_2_c,A_2_i_c;
int z=0;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QString currentpath= QDir::currentPath();
ui->setupUi(this);
ui->label_21->setTextInteractionFlags(Qt::TextSelectableByMouse);
setWindowIcon(QIcon(currentpath+"/images/logo.ico"));
QPixmap series(currentpath+"/images/RLCSeries1.png");
ui->label_15->setPixmap(series);
QPixmap parallel(currentpath+"/images/RLC parallel_1.png");
ui->label_16->setPixmap(parallel);
ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
ui->customPlot->axisRect()->setupFullAxesBox();
//Serial Default
ui->SVs->setValue(30); ui->SIo->setValue(0); ui->SVo->setValue(6);
ui->SRr->setValue(280); ui->SLr->setValue(2); ui->SCr->setValue(8.00);
ui->SC_unit->setCurrentIndex(1);
//Parallel Default
ui->PIs->setValue(4); ui->PIo->setValue(0); ui->PVo->setValue(250);
ui->PRr->setValue(500); ui->PLr->setValue(12.5); ui->PCr->setValue(50.00);
ui->PC_unit->setCurrentIndex(1);
if(alpha!=0)
{ err=(alpha-w0/alpha);
if(abs(err)<1E-4)
{
w0=alpha;
}
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::si_overdamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
s_1=-alpha + sqrt(pow(alpha,2)-w0_2);
s_2=-alpha - sqrt(pow(alpha,2)-w0_2);
A_1=(di-(s_2*i0))/(s_1-s_2);
A_2=(di-(s_1*i0))/(s_2-s_1);
t_f=6*__max(abs(1/s_1),abs(1/s_2));
do
{
vect_s_i.push_back((A_1*exp(s_1*t))+(A_2*exp(s_2*t)));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_i);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i(t) Overdamped");
// set axes ranges, so we see all data:
std::sort(vect_s_i.begin(),vect_s_i.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,15*/);
ui->customPlot->yAxis->setRange(vect_s_i.front(),vect_s_i.back());
ui->customPlot->replot();
}
void MainWindow::si_underdamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
qDebug()<<c<<"-"<<r;
t_f=6/alpha;
w_d=std::sqrt(std::complex<double>((w0_2-pow(alpha,2))));
c_s_1=-alpha + (j*w_d);
c_s_2=-alpha - (j*w_d);
A_1=i0; A_2_c=(di+(alpha*A_1))/w_d;
do
{
vect_s_i.push_back(real((exp(-alpha*t)*(A_1*cos(w_d*t)+A_2_c*sin(w_d*t)))));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_i);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i(t) Underdamped");
// set axes ranges, so we see all data:
std::sort(vect_s_i.begin(),vect_s_i.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_i.front(),vect_s_i.back());
ui->customPlot->replot();
}
void MainWindow::si_undamped(double v0,double vs,double i0,double l,double r,double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
t_f=8*(pi/w0);
w_d=w0;
A_1=i0; A_2_c=di/w_d;
do
{
vect_s_i.push_back(real((A_1*cos(w_d*t))+(A_2_c*sin(w_d*t))));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_i);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i(t) Undamped");
// set axes ranges, so we see all data:
std::sort(vect_s_i.begin(),vect_s_i.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_i.front(),vect_s_i.back());
ui->customPlot->replot();
}
void MainWindow::si_criticallyDamped(double v0,double vs,double i0,double l,double r,double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
s_1=-alpha; s_2=s_1;
A_2=i0; A_1=di+(alpha*A_2);
t_f=8/alpha;
do
{
vect_s_i.push_back(exp(-alpha*t)*((A_1*t)+A_2));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_i);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i(t) CriticallyDamped");
// set axes ranges, so we see all data:
std::sort(vect_s_i.begin(),vect_s_i.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_i.front(),vect_s_i.back());
ui->customPlot->replot();
}
void MainWindow::svc_overdamped(double v0,double vs,double i0,double l,double r,double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
s_1=-alpha + sqrt(pow(alpha,2)-w0_2);
s_2=-alpha - sqrt(pow(alpha,2)-w0_2);
A_1_i=((dv-s_2)*(v0-vs))/(s_1-s_2);
A_2_i=((dv-s_1)*(v0-vs))/(s_2-s_1);
t_f=6*__max(abs(1/s_1),abs(1/s_2));
do
{
vect_s_c.push_back(vs+(A_1_i*exp(s_1*t))+(A_2_i*exp(s_2*t)));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_c);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_C(t) Overdamped");
// set axes ranges, so we see all data:
std::sort(vect_s_c.begin(),vect_s_c.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_c.front(),vect_s_c.back()+5);
ui->customPlot->replot();
}
void MainWindow::svc_underdamped(double v0,double vs,double i0,double l,double r,double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
t_f=6/alpha;
w_d=std::sqrt(std::complex<double>((w0_2-pow(alpha,2))));
c_s_1=-alpha + (j*w_d);
c_s_2=-alpha - (j*w_d);
A_1_i=v0-vs; A_2_i_c=(dv+(alpha*A_1_i))/w_d;
do
{
vect_s_c.push_back(real(vs+(exp(-alpha*t)*((A_1_i*cos(w_d*t))+(A_2_i_c*sin(w_d*t))))));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_c);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_C(t) Underdamped");
// set axes ranges, so we see all data:
std::sort(vect_s_c.begin(),vect_s_c.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_c.front(),vect_s_c.back()+5);
ui->customPlot->replot();
}
void MainWindow::svc_undamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
t_f=8*(pi/w0);
w_d=w0;
A_1_i=v0-vs; A_2_i_c=dv/w_d;
do
{
vect_s_c.push_back(real(vs+(A_1_i*cos(w_d*t))+(A_2_i_c*sin(w_d*t))));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_c);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_C(t) Undamped");
// set axes ranges, so we see all data:
std::sort(vect_s_c.begin(),vect_s_c.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_c.front(),vect_s_c.back()+5);
ui->customPlot->replot();
}
void MainWindow::svc_criticallyDamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
s_1=-alpha; s_2=s_1;
A_2_i=v0-vs; A_1_i=dv+(alpha*A_2_i);
t_f=8/alpha;
do
{
vect_s_c.push_back(vs+(exp(-alpha*t)*(A_1_i*t+A_2_i)));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_c);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_C(t) CriticallyDamped");
// set axes ranges, so we see all data:
std::sort(vect_s_c.begin(),vect_s_c.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_c.front(),vect_s_c.back()+5);
ui->customPlot->replot();
}
void MainWindow::svr_overdamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
s_1=-alpha + sqrt(pow(alpha,2)-w0_2);
s_2=-alpha - sqrt(pow(alpha,2)-w0_2);
A_1=(di-(s_2*i0))/(s_1-s_2);
A_2=(di-(s_1*i0))/(s_2-s_1);
t_f=6*__max(abs(1/s_1),abs(1/s_2));
do
{
vect_s_r.push_back(r*((A_1*exp(s_1*t))+(A_2*exp(s_2*t))));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_r);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_R(t) Overdamped");
// set axes ranges, so we see all data:
std::sort(vect_s_r.begin(),vect_s_r.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_r.front(),vect_s_r.back());
ui->customPlot->replot();
}
void MainWindow::svr_underdamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
t_f=6/alpha;
w_d=sqrt(w0_2-pow(alpha,2));
c_s_1=-alpha + (j*w_d);
c_s_2=-alpha - (j*w_d);
A_1=i0; A_2_c=(di+(alpha*A_1))/w_d;
do
{
vect_s_r.push_back(real(r*(exp(-alpha*t)*(A_1*cos(w_d*t)+A_2_c*sin(w_d*t)))));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_r);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_R(t) Underdamped");
// set axes ranges, so we see all data:
std::sort(vect_s_r.begin(),vect_s_r.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_r.front(),vect_s_r.back());
ui->customPlot->replot();
}
void MainWindow::svr_undamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
t_f=8*(pi/w0);
w_d=w0;
A_1=i0; A_2_c=di/w_d;
do
{
vect_s_r.push_back(real(r*((A_1*cos(w_d*t))+(A_2_c*sin(w_d*t)))));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_r);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_R(t) Undamped");
// set axes ranges, so we see all data:
std::sort(vect_s_r.begin(),vect_s_r.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_r.front(),vect_s_r.back());
ui->customPlot->replot();
}
void MainWindow::svr_criticallyDamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
s_1=-alpha; s_2=s_1;
A_2=i0; A_1=di+(alpha*A_2);
t_f=8/alpha;
do
{
vect_s_r.push_back(r*(exp(-alpha*t)*((A_1*t)+A_2)));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
//qDebug()<<vect_s_i;
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_r);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_R(t) CriticallyDamped");
// set axes ranges, so we see all data:
std::sort(vect_s_r.begin(),vect_s_r.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_r.front(),vect_s_r.back());
ui->customPlot->replot();
}
void MainWindow::svl_overdamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
s_1=-alpha + sqrt(pow(alpha,2)-w0_2);
s_2=-alpha - sqrt(pow(alpha,2)-w0_2);
A_1=(di-(s_2*i0))/(s_1-s_2);
A_2=(di-(s_1*i0))/(s_2-s_1);
A_1_i=((dv-s_2)*(v0-vs))/(s_1-s_2);
A_2_i=((dv-s_1)*(v0-vs))/(s_2-s_1);
t_f=6*__max(abs(1/s_1),abs(1/s_2));
do
{
svc_L=vs+(A_1_i*exp(s_1*t))+(A_2_i*exp(s_2*t));
svr_L=r*((A_1*exp(s_1*t))+(A_2*exp(s_2*t)));
vect_s_l.push_back(vs-svr_L-svc_L);
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_l);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_L(t) Overdamped");
// set axes ranges, so we see all data:
std::sort(vect_s_l.begin(),vect_s_l.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_l.front(),vect_s_l.back());
ui->customPlot->replot();
}
void MainWindow::svl_underdamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
t_f=6/alpha;
w_d=sqrt(w0_2-pow(alpha,2));
c_s_1=-alpha + (j*w_d);
c_s_2=-alpha - (j*w_d);
A_1=i0; A_2_c=(di+(alpha*A_1))/w_d;
A_1_i=v0-vs; A_2_i_c=(dv+(alpha*A_1_i))/w_d;
do
{
svc_L=vs+(real(exp(-alpha*t)*((A_1_i*cos(w_d*t))+(A_2_i_c*sin(w_d*t)))));
svr_L=r*(real(exp(-alpha*t)*(A_1*cos(w_d*t)+A_2*sin(w_d*t))));
vect_s_l.push_back(vs-svr_L-svc_L);
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_l);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_L(t) Underdamped");
// set axes ranges, so we see all data:
std::sort(vect_s_l.begin(),vect_s_l.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_l.front(),vect_s_l.back());
ui->customPlot->replot();
}
void MainWindow::svl_undamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
t_f=8*(pi/w0);
w_d=w0;
A_1=i0; A_2_c=di/w_d;
A_1_i=v0-vs; A_2_i_c=dv/w_d;
do
{
svc_L=vs+(real((A_1_i*cos(w_d*t))+(A_2_i_c*sin(w_d*t))));
svr_L=r*(real((A_1*cos(w_d*t))+(A_2*sin(w_d*t))));
vect_s_l.push_back(vs-svr_L-svc_L);
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_l);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_L(t) Undamped");
// set axes ranges, so we see all data:
std::sort(vect_s_l.begin(),vect_s_l.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_l.front(),vect_s_l.back());
ui->customPlot->replot();
}
void MainWindow::svl_criticallyDamped(double v0, double vs, double i0, double l, double r, double c)
{
if(ui->SR_unit->currentIndex()==1)r=r*1000; else if(ui->SR_unit->currentIndex()==2)r=r*1E6;
if(ui->SL_unit->currentIndex()==1)l=l/1E3; else if(ui->SL_unit->currentIndex()==2)l=l/1E6;
if(ui->SC_unit->currentIndex()==1)c=c/1E6; else if(ui->SC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=r/(2*l);
di=(vs/l)-(v0/l)-(i0*r)/l;
dv=i0/c;
s_1=-alpha; s_2=s_1;
A_2=i0; A_1=di+(alpha*A_2);
A_2_i=v0-vs; A_1_i=dv+(alpha*A_2_i);
t_f=8/alpha;
do
{
svc_L=vs+(exp(-alpha*t)*(A_1_i*t+A_2_i));
svr_L=r*(exp(-alpha*t)*((A_1*t)+A_2));
vect_s_l.push_back(vs-svr_L-svc_L);
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_s_l);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v_L(t) CriticallyDamped");
// set axes ranges, so we see all data:
std::sort(vect_s_l.begin(),vect_s_l.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_s_l.front(),vect_s_l.back());
ui->customPlot->replot();
}
void MainWindow::pv_overdamped(double i_s,double i_0,double v_0,double l,double r,double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
s_1 = -alpha + sqrt(pow(alpha,2) - w0_2);
s_2 = -alpha - sqrt(pow(alpha,2) - w0_2);
A_1 = (dv-s_2*v_0)/(s_1-s_2); A_2 = (dv-s_1*v_0)/(s_2-s_1);
t_f = 6*__max(abs(1/s_1), abs(1/s_2));
do
{
vect_p_v.push_back((A_1*exp(s_1*t)+(A_2*exp(s_2*t))));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_v);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v(t) Overdamped");
// set axes ranges, so we see all data:
std::sort(vect_p_v.begin(),vect_p_v.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_v.front(),vect_p_v.back());
ui->customPlot->replot();
}
void MainWindow::pv_underdamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
t_f = 6/alpha;
w_d= sqrt(w0_2 - pow(alpha,2));
c_s_1 = -alpha +(j*w_d); c_s_2 = -alpha -(j*w_d);
A_1=v_0; A_2_c=(dv+(alpha*A_1))/w_d;
do
{
vect_p_v.push_back(real(exp(-alpha*t)*((A_1*cos(w_d*t))+(A_2_c*sin(w_d*t)))));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_v);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v(t) Underdamped");
// set axes ranges, so we see all data:
std::sort(vect_p_v.begin(),vect_p_v.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_v.front(),vect_p_v.back());
ui->customPlot->replot();
}
void MainWindow::pv_undamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
t_f = 8*(pi/w0);
w_d= w0;
A_1 = v_0; A_2_c = (dv)/w_d;
do
{
vect_p_v.push_back(real((A_1*cos(w_d*t))+A_2_c*sin(w_d*t)));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_v);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v(t) Undamped");
// set axes ranges, so we see all data:
std::sort(vect_p_v.begin(),vect_p_v.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_v.front(),vect_p_v.back());
ui->customPlot->replot();
}
void MainWindow::pv_criticallyDamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
s_1=-alpha; s_2=s_1;
A_2=v_0; A_1=dv+(alpha*A_2);
t_f=8/alpha;
do
{
vect_p_v.push_back(exp(-alpha*t)*(A_1*t+A_2));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_v);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("v(t) CriticallyDamped");
// set axes ranges, so we see all data:
std::sort(vect_p_v.begin(),vect_p_v.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_v.front(),vect_p_v.back());
ui->customPlot->replot();
}
void MainWindow::pil_overdamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
s_1 = -alpha + sqrt(pow(alpha,2) - w0_2);
s_2 = -alpha - sqrt(pow(alpha,2) - w0_2);
A_1_i = (di-s_2*(i_0-i_s))/(s_1-s_2); A_2_i = (di-s_1*(i_0-i_s))/(s_2-s_1);
t_f = 6*__max(abs(1/s_1), abs(1/s_2));
do
{
vect_p_i_l.push_back(i_s+(A_1_i*exp(s_1*t)+(A_2_i*exp(s_2*t))));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_l);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_L(t) Overdamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_l.begin(),vect_p_i_l.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_l.front(),vect_p_i_l.back());
ui->customPlot->replot();
}
void MainWindow::pil_underdamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
t_f = 6/alpha;
w_d= sqrt(w0_2 - pow(alpha,2));
c_s_1 = -alpha +(j*w_d); c_s_2 = -alpha -(j*w_d);
A_1_i=i_0-i_s; A_2_i_c=(di+(alpha*A_1_i))/w_d;
do
{
vect_p_i_l.push_back(real(i_s+(exp(-alpha*t)*((A_1_i*cos(w_d*t))+(A_2_i_c*sin(w_d*t))))));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_l);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_L(t) Underdamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_l.begin(),vect_p_i_l.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_l.front(),vect_p_i_l.back());
ui->customPlot->replot();
}
void MainWindow::pil_undamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
t_f = 8*(pi/w0);
w_d= w0;
A_1_i = i_0-i_s; A_2_i_c = (di)/w_d;
do
{
vect_p_i_l.push_back(real(i_s+(A_1_i*cos(w_d*t))+A_2_i_c*sin(w_d*t)));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_l);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_L(t) Undamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_l.begin(),vect_p_i_l.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_l.front(),vect_p_i_l.back());
ui->customPlot->replot();
}
void MainWindow::pil_criticallyDamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
s_1=-alpha; s_2=s_1;
A_2_i=i_0-i_s; A_1_i=di+(alpha*A_2_i);
t_f=8/alpha;
do
{
vect_p_i_l.push_back(i_s+(exp(-alpha*t)*(A_1_i*t+A_2_i)));
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_l);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_L(t) CriticallyDamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_l.begin(),vect_p_i_l.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_l.front(),vect_p_i_l.back());
ui->customPlot->replot();
}
void MainWindow::pir_overdamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
s_1 = -alpha + sqrt(pow(alpha,2) - w0_2);
s_2 = -alpha - sqrt(pow(alpha,2) - w0_2);
A_1 = (dv-s_2*v_0)/(s_1-s_2); A_2 = (dv-s_1*v_0)/(s_2-s_1);
t_f = 6*__max(abs(1/s_1), abs(1/s_2));
do
{
vect_p_i_r.push_back((A_1*exp(s_1*t)+(A_2*exp(s_2*t)))/r);
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_r);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_R(t) Overdamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_r.begin(),vect_p_i_r.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_r.front(),vect_p_i_r.back());
ui->customPlot->replot();
}
void MainWindow::pir_underdamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
t_f = 6/alpha;
w_d= sqrt(w0_2 - pow(alpha,2));
c_s_1 = -alpha +(j*w_d); c_s_2 = -alpha -(j*w_d);
A_1=v_0; A_2_c=(dv+(alpha*A_1))/w_d;
do
{
vect_p_i_r.push_back(real((exp(-alpha*t)*((A_1*cos(w_d*t))+(A_2_c*sin(w_d*t)))/r)));
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_r);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_R(t) Underdamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_r.begin(),vect_p_i_r.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_r.front(),vect_p_i_r.back());
ui->customPlot->replot();
}
void MainWindow::pir_undamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
t_f = 8*(pi/w0);
w_d= w0;
A_1 = v_0; A_2_c = (dv)/w_d;
do
{
vect_p_i_r.push_back(real((A_1*cos(w_d*t))+A_2_c*sin(w_d*t))/r);
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_r);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_R(t) Undamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_r.begin(),vect_p_i_r.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_r.front(),vect_p_i_r.back());
ui->customPlot->replot();
}
void MainWindow::pir_criticallyDamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
s_1=-alpha; s_2=s_1;
A_2=v_0; A_1=dv+(alpha*A_2);
t_f=8/alpha;
do
{
vect_p_i_r.push_back((exp(-alpha*t)*(A_1*t+A_2))/r);
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_r);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_R(t) CriticallyDamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_r.begin(),vect_p_i_r.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_r.front(),vect_p_i_r.back());
ui->customPlot->replot();
}
void MainWindow::pic_overdamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
s_1 = -alpha + sqrt(pow(alpha,2) - w0_2);
s_2 = -alpha - sqrt(pow(alpha,2) - w0_2);
A_1 = (dv-s_2*v_0)/(s_1-s_2); A_2 = (dv-s_1*v_0)/(s_2-s_1);
A_1_i = (di-s_2*(i_0-i_s))/(s_1-s_2); A_2_i = (di-s_1*(i_0-i_s))/(s_2-s_1);
t_f = 6*__max(abs(1/s_1), abs(1/s_2));
do
{
pir_C=(A_1*exp(s_1*t)+(A_2*exp(s_2*t)))/r;
pil_C=i_s+(A_1_i*exp(s_1*t)+(A_2_i*exp(s_2*t)));
vect_p_i_c.push_back(i_s-pir_C-pil_C);
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_c);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_C(t) Overdamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_c.begin(),vect_p_i_c.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_c.front(),vect_p_i_c.back());
ui->customPlot->replot();
}
void MainWindow::pic_underdamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
t_f = 6/alpha;
w_d= sqrt(w0_2 - pow(alpha,2));
c_s_1 = -alpha +(j*w_d); c_s_2 = -alpha -(j*w_d);
A_1=v_0; A_2_c=(dv+(alpha*A_1))/w_d;
A_1_i=i_0-i_s; A_2_i_c=(di+(alpha*A_1_i))/w_d;
do
{
pir_C=real((exp(-alpha*t)*((A_1*cos(w_d*t))+(A_2_c*sin(w_d*t)))/r));
pil_C=real(i_s+(exp(-alpha*t)*((A_1_i*cos(w_d*t))+(A_2_i_c*sin(w_d*t)))));
vect_p_i_c.push_back(i_s-pir_C-pil_C);
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_c);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_C(t) Underdamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_c.begin(),vect_p_i_c.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_c.front(),vect_p_i_c.back());
ui->customPlot->replot();
}
void MainWindow::pic_undamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
t_f = 8*(pi/w0);
w_d= w0;
A_1 = v_0; A_2_c = (dv)/w_d;
A_1_i = i_0-i_s; A_2_i_c = (di)/w_d;
do
{
pir_C=real((A_1*cos(w_d*t))+A_2_c*sin(w_d*t))/r;
pil_C=real(i_s+(A_1_i*cos(w_d*t))+A_2_i_c*sin(w_d*t));
vect_p_i_c.push_back(i_s-pir_C-pil_C);
vect_t.push_back(t);
t=t+(t_f/200);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_c);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_C(t) Undamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_c.begin(),vect_p_i_c.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_c.front(),vect_p_i_c.back());
ui->customPlot->replot();
}
void MainWindow::pic_criticallyDamped(double i_s, double i_0, double v_0, double l, double r, double c)
{
if(ui->PR_unit->currentIndex()==1)r=r*1000; else if(ui->PR_unit->currentIndex()==2)r=r*1E6;
if(ui->PL_unit->currentIndex()==1)l=l/1E3; else if(ui->PL_unit->currentIndex()==2)l=l/1E6;
if(ui->PC_unit->currentIndex()==1)c=c/1E6; else if(ui->PC_unit->currentIndex()==2)c=c/1E12;
w0_2=1/(l*c); w0=sqrt(w0_2); alpha=1/(2*r*c);
dv = (i_s/c)-(i_0/c)-v_0/(r*c);
di = v_0/l;
s_1=-alpha; s_2=s_1;
A_2=v_0; A_1=dv+(alpha*A_2);
A_2_i=i_0-i_s; A_1_i=di+(alpha*A_2_i);
t_f=8/alpha;
do
{
pir_C=(exp(-alpha*t)*(A_1*t+A_2))/r;
pil_C=i_s+(exp(-alpha*t)*(A_1_i*t+A_2_i));
vect_p_i_c.push_back(i_s-pir_C-pil_C);
vect_t.push_back(t);
t=t+(t_f/100);
}
while(t<=t_f);
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(vect_t,vect_p_i_c);
// give the axes some labels:
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("i_C(t) CriticallyDamped");
// set axes ranges, so we see all data:
std::sort(vect_p_i_c.begin(),vect_p_i_c.end());
std::sort(vect_t.begin(),vect_t.end());
ui->customPlot->xAxis->setRange(vect_t.front(),vect_t.back()/*0,0.1*/);
ui->customPlot->yAxis->setRange(vect_p_i_c.front(),vect_p_i_c.back());
ui->customPlot->replot();
}
void MainWindow::on_s_i_t_clicked()
{
t=0;
vect_s_i.clear();
vect_t.clear();
R=ui->SRr->value();L=ui->SLr->value();C=ui->SCr->value();
if(ui->SR_unit->currentIndex()==1)R=ui->SRr->value()*1000; else if(ui->SR_unit->currentIndex()==2)R=ui->SRr->value()*1E6;
if(ui->SL_unit->currentIndex()==1)L=ui->SLr->value()/1E3; else if(ui->SL_unit->currentIndex()==2)L=ui->SLr->value()/1E6;
if(ui->SC_unit->currentIndex()==1)C=ui->SCr->value()/1E6; else if(ui->SC_unit->currentIndex()==2)C=ui->SCr->value()/1E12;
w0_2=1/(L*C); w0=sqrt(w0_2); alpha=R/(2*L);
if(alpha>w0)
si_overdamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),
ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
if(alpha<w0)
{
if(alpha!=0)si_underdamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
else si_undamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
}
else if(alpha==w0)
si_criticallyDamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
}
void MainWindow::on_s_v_c_clicked()
{
t=0;
vect_s_c.clear();
vect_t.clear();
R=ui->SRr->value();L=ui->SLr->value();C=ui->SCr->value();
if(ui->SR_unit->currentIndex()==1)R=ui->SRr->value()*1000; else if(ui->SR_unit->currentIndex()==2)R=ui->SRr->value()*1E6;
if(ui->SL_unit->currentIndex()==1)L=ui->SLr->value()/1E3; else if(ui->SL_unit->currentIndex()==2)L=ui->SLr->value()/1E6;
if(ui->SC_unit->currentIndex()==1)C=ui->SCr->value()/1E6; else if(ui->SC_unit->currentIndex()==2)C=ui->SCr->value()/1E12;
w0_2=1/(L*C); w0=sqrt(w0_2); alpha=R/(2*L);
if(alpha>w0)
svc_overdamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),
ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
else if(alpha<w0)
{
if(alpha!=0)svc_underdamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
else svc_undamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
}
else if(alpha==w0)svc_criticallyDamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
}
void MainWindow::on_s_v_r_clicked()
{
t=0;
vect_s_r.clear();
vect_t.clear();
R=ui->SRr->value();L=ui->SLr->value();C=ui->SCr->value();
if(ui->SR_unit->currentIndex()==1)R=ui->SRr->value()*1000; else if(ui->SR_unit->currentIndex()==2)R=ui->SRr->value()*1E6;
if(ui->SL_unit->currentIndex()==1)L=ui->SLr->value()/1E3; else if(ui->SL_unit->currentIndex()==2)L=ui->SLr->value()/1E6;
if(ui->SC_unit->currentIndex()==1)C=ui->SCr->value()/1E6; else if(ui->SC_unit->currentIndex()==2)C=ui->SCr->value()/1E12;
w0_2=1/(L*C); w0=sqrt(w0_2); alpha=R/(2*L);
if(alpha>w0)
svr_overdamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),
ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
else if(alpha<w0)
{
if(alpha!=0)svr_underdamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
else svr_undamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
}
else if(alpha==w0)
svr_criticallyDamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
}
void MainWindow::on_s_v_l_clicked()
{
t=0;
vect_s_l.clear();
vect_t.clear();
R=ui->SRr->value();L=ui->SLr->value();C=ui->SCr->value();
if(ui->SR_unit->currentIndex()==1)R=ui->SRr->value()*1000; else if(ui->SR_unit->currentIndex()==2)R=ui->SRr->value()*1E6;
if(ui->SL_unit->currentIndex()==1)L=ui->SLr->value()/1E3; else if(ui->SL_unit->currentIndex()==2)L=ui->SLr->value()/1E6;
if(ui->SC_unit->currentIndex()==1)C=ui->SCr->value()/1E6; else if(ui->SC_unit->currentIndex()==2)C=ui->SCr->value()/1E12;
w0_2=1/(L*C); w0=sqrt(w0_2); alpha=R/(2*L);
if(alpha>w0)
svl_overdamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),
ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
else if(alpha<w0)
{
if(alpha!=0)svl_underdamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
else svl_undamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
}
else if(alpha==w0)svl_criticallyDamped(ui->SVo->value(),ui->SVs->value(),ui->SIo->value(),ui->SLr->value(),ui->SRr->value(),ui->SCr->value());
}
void MainWindow::on_p_v_t_clicked()
{
t=0;
vect_p_v.clear();
vect_t.clear();
R=ui->PRr->value();L=ui->PLr->value();C=ui->PCr->value();
if(ui->PR_unit->currentIndex()==1)R=R*1000; else if(ui->PR_unit->currentIndex()==2)R=R*1E6;
if(ui->PL_unit->currentIndex()==1)L=L/1E3; else if(ui->PL_unit->currentIndex()==2)L=L/1E6;
if(ui->PC_unit->currentIndex()==1)C=C/1E6; else if(ui->PC_unit->currentIndex()==2)C=C/1E12;
w0_2=1/(L*C); w0=sqrt(w0_2); alpha=1/(2*R*C);
if(alpha>w0)
pv_overdamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
else if(alpha<w0)
{
if(alpha!=0)
pv_underdamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
else
pv_undamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
}
else if(alpha==w0)
pv_criticallyDamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
}
void MainWindow::on_p_i_l_clicked()
{
t=0;
vect_p_i_l.clear();
vect_t.clear();
R=ui->PRr->value();L=ui->PLr->value();C=ui->PCr->value();
if(ui->PR_unit->currentIndex()==1)R=R*1000; else if(ui->PR_unit->currentIndex()==2)R=R*1E6;
if(ui->PL_unit->currentIndex()==1)L=L/1E3; else if(ui->PL_unit->currentIndex()==2)L=L/1E6;
if(ui->PC_unit->currentIndex()==1)C=C/1E6; else if(ui->PC_unit->currentIndex()==2)C=C/1E12;
w0_2=1/(L*C); w0=sqrt(w0_2); alpha=1/(2*R*C);
if(alpha>w0)
pil_overdamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
else if(alpha<w0)
{
if(alpha!=0)
pil_underdamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
else
pil_undamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
}
else if(alpha==w0)
pil_criticallyDamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
}
void MainWindow::on_p_i_r_clicked()
{
t=0;
vect_p_i_r.clear();
vect_t.clear();
R=ui->PRr->value();L=ui->PLr->value();C=ui->PCr->value();
if(ui->PR_unit->currentIndex()==1)R=R*1000; else if(ui->PR_unit->currentIndex()==2)R=R*1E6;
if(ui->PL_unit->currentIndex()==1)L=L/1E3; else if(ui->PL_unit->currentIndex()==2)L=L/1E6;
if(ui->PC_unit->currentIndex()==1)C=C/1E6; else if(ui->PC_unit->currentIndex()==2)C=C/1E12;
w0_2=1/(L*C); w0=sqrt(w0_2); alpha=1/(2*R*C);
if(alpha>w0)
pir_overdamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
else if(alpha<w0)
{
if(alpha!=0)
pir_underdamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
else
pir_undamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
}
else if(alpha==w0)
pir_criticallyDamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
}
void MainWindow::on_p_i_c_clicked()
{
t=0;
vect_p_i_c.clear();
vect_t.clear();
R=ui->PRr->value();L=ui->PLr->value();C=ui->PCr->value();
if(ui->PR_unit->currentIndex()==1)R=R*1000; else if(ui->PR_unit->currentIndex()==2)R=R*1E6;
if(ui->PL_unit->currentIndex()==1)L=L/1E3; else if(ui->PL_unit->currentIndex()==2)L=L/1E6;
if(ui->PC_unit->currentIndex()==1)C=C/1E6; else if(ui->PC_unit->currentIndex()==2)C=C/1E12;
w0_2=1/(L*C); w0=sqrt(w0_2); alpha=1/(2*R*C);
if(alpha>w0)
pic_overdamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
else if(alpha<w0)
{
if(alpha!=0)
pic_underdamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
else
pic_undamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
}
else if(alpha==w0)
pic_criticallyDamped(ui->PIs->value(),ui->PIo->value(),ui->PVo->value(),ui->PLr->value(),ui->PRr->value(),ui->PCr->value());
}