Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented calculus without Ea #12

Merged
merged 1 commit into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified rootprox-2022/.vs/rootprox-2022/v16/.suo
Binary file not shown.
204 changes: 114 additions & 90 deletions rootprox-2022/Forms/Methods/ROOTPROX - Bisección.Designer.cs

Large diffs are not rendered by default.

240 changes: 196 additions & 44 deletions rootprox-2022/Forms/Methods/ROOTPROX - Bisección.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public ROOTPROX_Bisección(string currentTheme)

private void ROOTPROX_Bisección_Load(object sender, EventArgs e)
{
dgvResultAprox.ColumnHeadersDefaultCellStyle.BackColor = ColorsTheme.PanelContainerLeft;
dgvResultAprox.GridColor = ColorsTheme.PanelContainerLeft;
dgvResultAprox.ColumnHeadersDefaultCellStyle.BackColor = ColorsTheme.PanelContainerLeft; // Cabezera
dgvResultAprox.GridColor = ColorsTheme.PanelSubMenu; // Lineas

dgvResults.ColumnHeadersDefaultCellStyle.BackColor = ColorsTheme.PanelContainerLeft;
dgvResults.GridColor = ColorsTheme.PanelContainerLeft;
dgvResults.ColumnHeadersDefaultCellStyle.BackColor = ColorsTheme.PanelContainerLeft; // Cabezera
dgvResults.GridColor = ColorsTheme.PanelSubMenu; // Lineas
}

// Functions
Expand Down Expand Up @@ -90,7 +90,7 @@ private double function(double x)

private void btnCalculate_Click(object sender, EventArgs e)
{
int imax, iter;
int imax, iter, round;
double xi, xd, ea, em, xa, xaold;

/* xi = a
Expand All @@ -102,69 +102,217 @@ private void btnCalculate_Click(object sender, EventArgs e)
* imax = iteraciones maximas
*/

xi = double.Parse(txtA.Text);
xd = double.Parse(txtB.Text);
em = double.Parse(txtE.Text);
imax = int.Parse(txtNmax.Text);
txtBoxEmpty(gbValues); // Determina si hay TextBox vacíos.
txtBoxContains(gbValues); // Determina si algunos de los TextBox tengan solamente - o punto.

dgvResults.Rows.Clear();
dgvResultAprox.Rows.Clear();

iter = 0;
xa = 0;

if (function(xi) * function(xd) > 0)
if (txtEmpty == true || txtContains == true) // Si hay algún TextBox vacío o únicamente con - o punto.
{
MessageBox.Show("No existe raíz en esos intérvalos.");
MessageBox.Show(
"No se admiten campos con valores inválidos, por favor rellene correctamente los campos para continuar.\n\n" +
"Da click en el botón AYUDA para obtener más información.\n\n" +
"Código: A100",
"Advertencia",
MessageBoxButtons.OK,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1,
0, "https://google.com"
);

txtEmpty = false; // Se reinicia la variable si ya se había encontrado un TextBox vacío.
txtContains = false; // Se reinicia la variable si ya se había encontrado un TextBox con - o punto.
}
else
{
do
{
iter++;
xi = double.Parse(txtA.Text);
xd = double.Parse(txtB.Text);
em = double.Parse(txtE.Text);
imax = int.Parse(txtNmax.Text);

xaold = xa;
xa = (xi + xd) / 2;
dgvResults.Rows.Clear();
dgvResultAprox.Rows.Clear();

ea = Math.Abs((xa - xaold) / xa) * 100;
iter = 0;
xa = 0;

if (function(xi) * function(xa) < 0)
{
xd = xa;
}
else if (function(xi) * function(xa) > 0)
{
xi = xa;
}
else
if (function(xi) * function(xd) > 0)
{
MessageBox.Show("No existe raíz en esos intérvalos.");
}
else
{
if (cbSinEA.Checked == true)
{
ea = 0;
}
if (rbRedondear.Checked == true)
{
round = Convert.ToInt32(Math.Round(numericRound.Value, 0));

do
{
iter++;

xa = (xi + xd) / 2;

int n1 = dgvResults.Rows.Add();

int n1 = dgvResults.Rows.Add();
dgvResults.Rows[n1].Cells[1].Value = xi;
dgvResults.Rows[n1].Cells[2].Value = xd;

dgvResults.Rows[n1].Cells[0].Value = iter;
dgvResults.Rows[n1].Cells[1].Value = xa;
dgvResults.Rows[n1].Cells[2].Value = ea + " %";
if (function(xi) * function(xa) < 0)
{
xd = xa;
}
else
{
xi = xa;
}

} while (ea > em && iter <= imax);
dgvResults.Rows[n1].Cells[0].Value = iter;
dgvResults.Rows[n1].Cells[3].Value = Math.Round(xa, round);

int n2 = dgvResultAprox.Rows.Add();
} while (iter <= imax);

dgvResultAprox.Rows[n2].Cells[0].Value = iter;
dgvResultAprox.Rows[n2].Cells[1].Value = xa;
dgvResultAprox.Rows[n2].Cells[2].Value = ea + " %";
int n2 = dgvResultAprox.Rows.Add();

dgvResultAprox.Rows[n2].Cells[0].Value = iter;
dgvResultAprox.Rows[n2].Cells[1].Value = Math.Round(xa, round);
}
else
{
do
{
iter++;

xa = (xi + xd) / 2;

int n1 = dgvResults.Rows.Add();

dgvResults.Rows[n1].Cells[1].Value = xi;
dgvResults.Rows[n1].Cells[2].Value = xd;

if (function(xi) * function(xa) < 0)
{
xd = xa;
}
else
{
xi = xa;
}

dgvResults.Rows[n1].Cells[0].Value = iter;
dgvResults.Rows[n1].Cells[3].Value = xa;

} while (iter <= imax);

int n2 = dgvResultAprox.Rows.Add();

dgvResultAprox.Rows[n2].Cells[0].Value = iter;
dgvResultAprox.Rows[n2].Cells[1].Value = xa;
}
}
else
{
if (rbRedondear.Checked == true)
{
round = Convert.ToInt32(Math.Round(numericRound.Value, 0));

do
{
iter++;

xaold = xa;
xa = (xi + xd) / 2;

ea = Math.Abs((xa - xaold) / xa) * 100;

int n1 = dgvResults.Rows.Add();

dgvResults.Rows[n1].Cells[1].Value = xi;
dgvResults.Rows[n1].Cells[2].Value = xd;

if (function(xi) * function(xa) < 0)
{
xd = xa;
}
else if (function(xi) * function(xa) > 0)
{
xi = xa;
}
else
{
ea = 0;
}

dgvResults.Rows[n1].Cells[0].Value = iter;
dgvResults.Rows[n1].Cells[3].Value = Math.Round(xa, round);
dgvResults.Rows[n1].Cells[4].Value = ea + " %";

} while (ea > em && iter <= imax);

int n2 = dgvResultAprox.Rows.Add();

dgvResultAprox.Rows[n2].Cells[0].Value = iter;
dgvResultAprox.Rows[n2].Cells[1].Value = Math.Round(xa, round);
dgvResultAprox.Rows[n2].Cells[2].Value = ea + " %";
}
else
{
do
{
iter++;

xaold = xa;
xa = (xi + xd) / 2;

ea = Math.Abs((xa - xaold) / xa) * 100;

int n1 = dgvResults.Rows.Add();

dgvResults.Rows[n1].Cells[1].Value = xi;
dgvResults.Rows[n1].Cells[2].Value = xd;

if (function(xi) * function(xa) < 0)
{
xd = xa;
}
else if (function(xi) * function(xa) > 0)
{
xi = xa;
}
else
{
ea = 0;
}

dgvResults.Rows[n1].Cells[0].Value = iter;
dgvResults.Rows[n1].Cells[3].Value = xa;
dgvResults.Rows[n1].Cells[4].Value = ea + " %";

} while (ea > em && iter <= imax);

int n2 = dgvResultAprox.Rows.Add();

dgvResultAprox.Rows[n2].Cells[0].Value = iter;
dgvResultAprox.Rows[n2].Cells[1].Value = xa;
dgvResultAprox.Rows[n2].Cells[2].Value = ea + " %";
}
}
}
}
}

private void btnReset_Click(object sender, EventArgs e)
{
if (MessageBox.Show("¿Desea reiniciar los valores?", "Advertencia", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
if (MessageBox.Show("¿Desea reiniciar los valores?", "Reiniciar", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
Reset();
}
}

private void numericRound_ValueChanged(object sender, EventArgs e)
{

}

private void txtFX_KeyPress(object sender, KeyPressEventArgs e)
{
onlyNumbersAndFunctions(sender, e);
Expand Down Expand Up @@ -265,11 +413,15 @@ private void cbSinEA_CheckedChanged(object sender, EventArgs e)
txtE.Enabled = false;
txtE.Visible = false;
lblPor100.Visible = false;
dgvResultAprox.Columns.RemoveAt(2);
dgvResults.Columns.RemoveAt(4);
lblError.Text = "Sin Factor de Paro (εa)";
}
else
{
lblError.Text = "Factor de Paro (εa) =";
dgvResultAprox.Columns.Add("ea", "Error Relativo Aproximado");
dgvResults.Columns.Add("ea", "Error Relativo Aproximado");
txtE.Enabled = true;
txtE.Visible = true;
lblPor100.Visible = true;
Expand Down
6 changes: 6 additions & 0 deletions rootprox-2022/Forms/Methods/ROOTPROX - Bisección.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
<metadata name="iter.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="X0.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="X1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="xr.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
Expand Down
Binary file modified rootprox-2022/bin/Debug/rootprox-2022.exe
Binary file not shown.
Binary file modified rootprox-2022/bin/Debug/rootprox-2022.pdb
Binary file not shown.
Binary file modified rootprox-2022/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.
Binary file not shown.
Binary file modified rootprox-2022/obj/Debug/rootprox-2022.exe
Binary file not shown.
Binary file modified rootprox-2022/obj/Debug/rootprox-2022.pdb
Binary file not shown.