注册 登录
编程论坛 C++ Builder

C++builder如何实现牛顿迭代?求大神指点。

元龙高卧 发布于 2013-06-12 19:32, 1508 次点击
最近编程需要解一维超越方程,和导师要了一份模板,但是定义牛顿迭代时不能直接复制过去。代码及错误原因如下:(蓝色部分是直接复制过去的)求指导,谢谢

void __fastcall TForm3::Button5Click(TObject *Sender)//管道厚度计算
{
    int t0,ta,ts;
    float t1,q,a,l,l1,l2,D0,D1,b,b1,b2,length;
    ……………………………………     
    中间部分省略   
   …………………………………………
        
    if(rbt9->Checked==true)              //单层保温
    {
       float m,total;
      x=newton_diedai(x,&n,jingdu,t,ta,q,D0,a,l);      //外经计算X=D1
      b=(x-D0)/2;                                      //厚度计算
      edt10->Text=FloatToStrF(b,ffFixed,5,2);          //厚度输出
      m=StrToFloat(Edit6->Text);
      total=3.1415926*(x*x/4/1000000-D0*D0/4/1000000)*length*m;//投资计算
     Edit10->Text=FloatToStrF(total,ffFixed,5,2);       //投资输出
           }
     
//---------------------------------------------------------------------------
  /*
double TForm3::newton_diedai(double x0, int * n, double jingdu, int t, int ta, float q, float D0, float a, float l)
{
                                                  //TODO: Add your source code here        //在这里添加你的源代码

         double x,temp;
     temp=function1(x0,D0,a,l);
     if(fabs(temp)>1e-10)                     //temp的绝对值大于0.000001
         x=x0-function(x0,t,ta,q,D0,a,l)/temp;
     else
         exit(1);
         if(++(*n)>MAX_DIEDAI_TIME)
        exit(1);
        temp=function(x,t,ta,q,D0,a,l);
        if(fabs(temp)<jingdu )
      return x;
      else
      return newton_diedai(x,n,jingdu,t,ta,q,D0,a,l)     ;

}

double TForm3::function(double x, int t, int ta, float q, float D0, float a, float l)
{
        //TODO: Add your source code here
        return log(x/D0)/l+2000/a/x-2*3.1415926*(t-ta)/q;
}

double TForm3::function1(double x, float D0, float a, float l)
{
        //TODO: Add your source code here
        return D0/x/l-2000/a/x/x;
}
  */
double __fastcall TForm3::newton_diedai(double x0, int * n, double jingdu, int t, int ta, float q, float D0, float a, float l)
{
        //TODO: Add your source code here
        double x,temp;
     temp=function1(x0,D0,a,l);
     if(fabs(temp)>1e-10)
         x=x0-function(x0,t,ta,q,D0,a,l)/temp;
     else
         exit(1);
         if(++(*n)>MAX_DIEDAI_TIME)
        exit(1);
        temp=function(x,t,ta,q,D0,a,l);
        if(fabs(temp)<jingdu )
      return x;
      else
      return newton_diedai(x,n,jingdu,t,ta,q,D0,a,l) ;

}

double __fastcall TForm3::function(double x, int t, int ta, float q, float D0, float a, float l)
{
        //TODO: Add your source code here
         return x*log(x/D0)/l+2000/a-2*1000*(t-ta)/q;
}

double __fastcall TForm3::function1(double x, float D0, float a, float l)
{
        //TODO: Add your source code here
        return (log(x/D0)+D0)/l;
}

错误原因


[C++ Error] Unit2.cpp(393): E2268 Call to undefined function 'newton_diedai'
[C++ Error] Unit2.cpp(450): E2316 '_fastcall TForm2::newton_diedai(double,int *,double,int,int,float,float,float,float)' is not a member of 'TForm2'
[C++ Error] Unit2.cpp(469): E2316 '_fastcall TForm2::function(double,int,int,float,float,float,float)' is not a member of 'TForm2'
[C++ Error] Unit2.cpp(475): E2316 '_fastcall TForm2::function1(double,float,float,float)' is not a member of 'TForm2'
1 回复
#2
hxj19872014-11-13 22:33
回复 楼主 元龙高卧
double __fastcall TForm3::function(double x, int t, int ta, float q, float D0, float a, float l)等函数应该在Unit3.h主类中进行声明
1