MC68HC11 Quadratic Equation

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MC68HC11 Quadratic Equation

1,494 次查看
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 回复数

775 次查看
junkbonkin
Contributor I
unfortunately i am using one that can only take mnemonic code or opcode but thank you for the help
0 项奖励
回复

775 次查看
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 项奖励
回复