#include "led.h"
#include "delay.h"
#include "sys.h"
#include "stdio.h"
#include "math.h"
#include<stdlib.h>
struct ROOM
{
double buf[3];
};
double f(double x)
{
double y;
y=sqrt(2*x+3);
return y;
}
struct ROOM diedai(double x0,double Error,u8 N)
{
double x1;
int i,k;
struct ROOM a;
u8 n=0;
for(k=0;k<N;k++)
{x1=f(x0);
if(fabs(x1-x0)<Error)
{
a.buf[0]=k;
a.buf[1]=x1;
a.buf[2]=n;
break;
}
else x0=x1;//在这里赋值,进行递推
n++;
}
if(k>=N)
{
a.buf[0]=k;
a.buf[1]=x1;
a.buf[2]=n;
}
return a;
}
int main(void)
{
int i,j;
struct ROOM res;
delay_init(); //延时函数初始化
while(1)
{
res=diedai(4.0,0.1,15);
}
} |