MC68HC11 Quadratic Equation

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MC68HC11 Quadratic Equation

1,500件の閲覧回数
junkbonkin
Contributor I
I Am trying to write a small program to solve the quadratic equation and i was wondering if anyone could help the numbers are A=1 B=4 and C=5 thanks for your help in advance and also does anyone know of a good free ware 68hc11 emulator i had THRsim11 but the trial is almost over thank you in advance
ラベル(1)
0 件の賞賛
返信
2 返答(返信)

781件の閲覧回数
junkbonkin
Contributor I
unfortunately i am using one that can only take mnemonic code or opcode but thank you for the help
0 件の賞賛
返信

781件の閲覧回数
bigmac
Specialist III
Hello,
 
Assuming you have resources to accommodate floating point mathematics, the following untested function should give the solutions to the quadradic equation, for both real and complex cases.
 
#include "math.h"
 
/* Global variables for result */
double r1, i1;  // First solution
double r2, i2;  // Second solution
 
void quadratic (double a, double b, double c)
{
  double t;
 
  b = b/a;
  c = c/a;
  t = b*b/2 - c;
  if (t < 0)  {
     /* Complex solution */
     r1 = -0.5*b;
     i1 = sqrt(-t);
     r2 = r1;
     i2 = -i1;
  }
  else {
     /* Real solution */
     t = sqrt(t);
     r1 = -0.5*b + t;
     i1 = 0;
     r2 = -0.5*b - t;
     i2 = 0;
  }
}
 
For the coefficients given in your post, the solution will be complex -
-2+j1, -2-j1
 
Regards,
Mac
 
0 件の賞賛
返信