标题:C++builder如何实现牛顿迭代?求大神指点。
只看楼主
元龙高卧
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-6-7
 问题点数:0 回复次数:1 
C++builder如何实现牛顿迭代?求大神指点。
最近编程需要解一维超越方程,和导师要了一份模板,但是定义牛顿迭代时不能直接复制过去。代码及错误原因如下:(蓝色部分是直接复制过去的)求指导,谢谢

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'
搜索更多相关主题的帖子: 管道 如何 
2013-06-12 19:32
hxj1987
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-11-13
得分:0 
回复 楼主 元龙高卧
double __fastcall TForm3::function(double x, int t, int ta, float q, float D0, float a, float l)等函数应该在Unit3.h主类中进行声明
2014-11-13 22:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-415053-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021229 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved