public string mostraNovaEquacao() { /*var s = Expr.Variable("s"); * var t = Expr.Variable("t");*/ //MessageBox.Show("Equação geral: " + aL + "s² + " + cL + "t² - " + aL * cL + " = 0"); double[] num = { getAL(), getBL(), getCL(), getDL(), getEL(), getF() }; double max = 0; for (int i = 0; i < 6; i++) { if (num[i] > max) { max = num[i]; } } long[] num2 = { (long)max, (long)max, (long)max, (long)max, (long)max, (long)max }; int j = 0; for (int i = 0; i < 6; i++) { if (num[i] != 0) { num2[j] = (long)num[i]; j++; } } double div = (double)Euclid.GreatestCommonDivisor(num2); MessageBox.Show("MMC: " + div); if (div != null && div != 0) { setAL(getAL() / div); setBL(getBL() / div); setCL(getCL() / div); setDL(getDL() / div); setEL(getEL() / div); setF(getF() / div); } // Simplifica a equação com o maior divisor entre eles var eq = Infix.ParseOrThrow(getAL().ToString() + "*u*u+" + getBL().ToString() + "*u*v+" + getCL().ToString() + "*v*v+" + getDL().ToString() + "*u+" + getEL().ToString() + "*v+" + getF().ToString()); var expanded = Algebraic.Expand(eq); MessageBox.Show("Equação Geral: " + Infix.FormatStrict(expanded), "Equação", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // Agora falta simplificar a equação return(Infix.FormatStrict(expanded).ToString()); }
public void calculaH_K(double[] coeficientes) { double a = coeficientes[0]; double b = coeficientes[1]; double c = coeficientes[2]; double d = coeficientes[3]; double e = coeficientes[4]; double f = coeficientes[5]; var A = Matrix <double> .Build.DenseOfArray(new double[, ] { { Convert.ToInt32(a), Convert.ToInt32(b / 2) }, { Convert.ToInt32(b / 2), Convert.ToInt32(c) }, }); MessageBox.Show("Matriz para calcular H e K: " + A.ToString()); var B = Vector <double> .Build.Dense(new double[] { -(d / 2), -(e / 2) }); var x = A.Solve(B); MessageBox.Show("H e K: " + x.ToString()); h = x[0]; k = x[1]; if (!Double.IsInfinity(getH())) // Se o determinante deu diferente de zero foi possível realizar a translação { // Achar o novo termo independente da equação: (p.96) setF((getD() / 2) * getH() + (getE() / 2) * getK() + getF()); var eq = Infix.ParseOrThrow(getA().ToString() + "*u*u+" + getB().ToString() + "*u*v+" + getC().ToString() + "*v*v+" + getF().ToString()); var expanded = Algebraic.Expand(eq); MessageBox.Show("Translação realizada!\nNova equação da cônica:\n" + Infix.FormatStrict(expanded) + " ", "Translação Concluida", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); MessageBox.Show("Iniciando Rotação para elimianar o termo quadrático misto", "Iniciando Rotação", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
//mostraNovaEquacao2 retorna a equação após fazer a rotação e a translação conforme o caso na pag 99 das notas de aula public string mostraNovaEquacao2() { // O termo independente continua o mesmo pois não foi realizada a translação double[] num = { getAL(), getBL(), getCL(), getDL(), getEL(), getF() }; double max = 0; for (int i = 0; i < 6; i++) { if (num[i] > max) { max = num[i]; } } long[] num2 = { (long)max, (long)max, (long)max, (long)max, (long)max, (long)max }; int j = 0; for (int i = 0; i < 6; i++) { if (num[i] != 0) { num2[j] = (long)num[i]; j++; } } double div = (double)Euclid.GreatestCommonDivisor(num2); MessageBox.Show("MMC: " + div); if (div != null && div != 0) { setAL(getAL() / div); setBL(getBL() / div); setCL(getCL() / div); setDL(getDL() / div); setEL(getEL() / div); setF(getF() / div); } // Simplifica a equação com o maior divisor entre eles var eq = Infix.ParseOrThrow(getAL().ToString() + "*u*u+" + getBL().ToString() + "*u*v+" + getCL().ToString() + "*v*v+" + getDL().ToString() + "*u+" + getEL().ToString() + "*v+" + getF().ToString()); var expanded = Algebraic.Expand(eq); MessageBox.Show("Equação Geral: " + Infix.FormatStrict(expanded), "Equação", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(Infix.FormatStrict(expanded).ToString()); // B = 0 // Agora simplificar a equação }
public static void CalculateEquation(ref Dictionary <string, FloatingPoint> initialVector, int i) { var df1x = Calculus.Differentiate(x, f1); var df1y = Calculus.Differentiate(y, f1); var df2x = Calculus.Differentiate(x, f2); var df2y = Calculus.Differentiate(y, f2); double j11 = Eval.Evaluate(initialVector, df1x).RealValue; double j12 = Eval.Evaluate(initialVector, df1y).RealValue; double j21 = Eval.Evaluate(initialVector, df2x).RealValue; double j22 = Eval.Evaluate(initialVector, df2y).RealValue; if (i == 1) { Console.WriteLine("Jacobian matrix symbolic:"); Console.WriteLine(Infix.FormatStrict(df1x) + " " + Infix.Format(df1y) + "\n" + Infix.Format(df2x) + " " + Infix.Format(df2y)); } double[] m = { j11, j21, j12, j22 }; Matrix <double> jacobian = new DenseMatrix(2, 2, m); Console.WriteLine("Jacobian matrix numeric:\n"); Console.WriteLine(jacobian.ToString()); Matrix <double> initial = new DenseMatrix(2, 1, new double[] { Eval.Evaluate(initialVector, f1).RealValue, Eval.Evaluate(initialVector, f2).RealValue }); jacobian = jacobian.Inverse(); var solution = jacobian * (-initial); var xn = x0 + solution[0, 0]; var yn = y0 + solution[1, 0]; var outVal = new Dictionary <string, FloatingPoint> { { "x", xn }, { "y", yn } }; Console.WriteLine("Iteration " + i + ":\n"); Console.WriteLine("x" + i.ToString() + " = " + xn + Environment.NewLine + "y" + i.ToString() + " = " + yn); Console.WriteLine("f1(x" + i + ",y" + i + ")=" + Math.Round(Eval.Evaluate(initialVector, f1).RealValue, 3)); Console.WriteLine("f2(x" + i + ",y" + i + ")=" + Eval.Evaluate(initialVector, f2).RealValue); Console.WriteLine("\n"); initialVector = outVal; x0 = xn; y0 = yn; }