#include "stm8s.h"
float SF6(float t, float p, float x)
{
float a, b;
a = (74.9e-6)*(1 - (0.727e-3)*x);
b = (2.51e-3)*x*(1 - (0.846e-3)*x);
return (56.2e-6)*x*t*(1 + b) - x*x*a - p;
}
float SF6Root(float t, float p)
{
float x0, x1, x2;
int i;
float eps = 0.001;
x0 = -40;
x1 = 190;
for(i = 1; i <= 100; i++)
{
x2 = x1-(SF6(t,p,x1)*(x1-x0))/(SF6(t,p,x1)-SF6(t,p,x0));
if((x2-x1)<eps && SF6(t,p,x2)<eps && (x1-x2)<eps && SF6(t,p,x2)>(0-eps))break;
x0 = x1;
x1 = x2;
}
return x2;
}
|