diff --git a/lib/solver.dart b/lib/solver.dart index c37da49..3869960 100644 --- a/lib/solver.dart +++ b/lib/solver.dart @@ -243,11 +243,29 @@ class SolverService { CalculationStep( stepNumber: 4, title: '判断解', - explanation: r'因为 $\Delta < 0$,该方程在实数范围内无解。', - formula: '无实数解', + explanation: r'因为 $\Delta < 0$,该方程在实数范围内无解,但有虚数解。', + formula: '无实数解,有虚数解', ), ); - return CalculationResult(steps: steps, finalAnswer: '无实数解'); + + final sqrtDelta = sqrt(-delta); + final realPart = -b / (2 * a); + final imagPart = sqrtDelta / (2 * a); + + steps.add( + CalculationStep( + stepNumber: 5, + title: '计算虚数根', + explanation: '使用求根公式计算虚数根。', + formula: r'$$x = \frac{-b \pm \sqrt{-\Delta} i}{2a}$$', + ), + ); + + return CalculationResult( + steps: steps, + finalAnswer: + '\$\$x_1 = ${realPart.toStringAsFixed(4)} + ${imagPart.toStringAsFixed(4)}i, \\quad x_2 = ${realPart.toStringAsFixed(4)} - ${imagPart.toStringAsFixed(4)}i\$\$', + ); } } @@ -270,12 +288,12 @@ class SolverService { explanation: '这是一个二元一次方程组,我们将使用加减消元法求解。', formula: ''' - +\$\$ \\begin{cases} -${a1}x ${b1 >= 0 ? '+' : ''} ${b1}y = $c1 & (1) \\ +${a1}x ${b1 >= 0 ? '+' : ''} ${b1}y = $c1 & (1) \\\\ ${a2}x ${b2 >= 0 ? '+' : ''} ${b2}y = $c2 & (2) \\end{cases} - +\$\$ ''', ), ); @@ -344,9 +362,9 @@ ${newA2}x ${b1 * b2 >= 0 ? '+' : ''} ${b1 * b2}y = $newC2 & (4) ''' \\begin{aligned} -$a2($x) + ${b2}y &= $c2 \\ -${a2 * x} + ${b2}y &= $c2 \\ -${b2}y &= $c2 - ${a2 * x} \\ +$a2($x) + ${b2}y &= $c2 \\\\ +${a2 * x} + ${b2}y &= $c2 \\\\ +${b2}y &= $c2 - ${a2 * x} \\\\ ${b2}y &= ${c2 - a2 * x} \\end{aligned} @@ -378,9 +396,9 @@ ${b2}y &= ${c2 - a2 * x} ''' \\begin{aligned} -$a1($x) + ${b1}y &= $c1 \\ -${a1 * x} + ${b1}y &= $c1 \\ -${b1}y &= $c1 - ${a1 * x} \\ +$a1($x) + ${b1}y &= $c1 \\\\ +${a1 * x} + ${b1}y &= $c1 \\\\ +${b1}y &= $c1 - ${a1 * x} \\\\ ${b1}y &= ${c1 - a1 * x} \\end{aligned} diff --git a/pubspec.yaml b/pubspec.yaml index 1fcc44d..ba6acd4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+2 +version: 1.0.0+3 environment: sdk: ^3.9.2