回 帖 发 新 帖 刷新版面

主题:求大大们帮我看下这是为什么

/* 程序使用说明:
E1—终止迭代收敛精度;
ep—复合形法中映射系数α给定的最小取值δ,一般取δ=0.00001;
n—设计变量的维数;
k—复合形的顶点数;
af—初始映射系数。*/
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#define E1 0.0001
#define ep 0.0001
#define n 2
#define k 4
float af=10;
int i,j;
double X0[n],XX[n],X[k][n],FF[k];
void produce(double A[n],double B[n]);                           /* 产生k个复合形顶点 */
double a[n],b[n];
double F(double C[n]);                                           /* 目标函数 */
int cons(double D[n]);                                           /* 约束函数 */
void bou();                                                      /* 给出边界条件 */
double *Complex();
/* 制定这样的例子 */
double F(double C[n])
{
    double F;
    F=25/(C[0]*C[1]*C[1]*C[1]);                                  /* 目标函数 */
    return F;
}
/* 检查在约束条件下可选择顶点的可行性 */
int cons(double D[n])
{
    if(((30/D[0]*D[1]*D[1]-50)<=0)&&((0.0004*D[1]-0.001)<=0)&&
        ((D[0]>=2)&&(D[0]<=4))&&((D[1]>=0.5)&&(D[1]<=1)))        /* 约束条件 */
        return 1;
    else
        return 0;
}
void bou()                                                       /* 给出设计变量的边界条件 */
{
    a[0]=2;
    a[1]=0.5;
    b[0]=4;
    b[1]=1;
}
void produce(double A[n],double B[n])                            /* 产生复合形的k个顶点 */
{
    double rr;
    int jj;
    do
    {
        rr=rand();
        rr=rr/32767;
        for(i=0;i<n;i++)
        {
            X[0][i]=A[i]+rr*(B[i]-A[i]);
            XX[i]=X[0][i];
        }
    }
    while(cons(XX)==0);
    for(j=1;j<k;j++)                                            /* 生成其他的k-1个顶点 */
    {
        rr=rand();
        rr=rr/32767;
        for(i=0;i<n;i++)
        {
            X[j][i]=A[i]+rr*(B[i]-A[i]);
        }
    }
    for(j=0;j<k;j++)                                            /* 检查每个点的可行性 */
    {
        for(i=0;i<n;i++)
        {
            X0[i]=0;
            for(jj=0;jj<j+1;j++)
            {
                X0[i]+=X[jj][i];
            }
            X0[i]=(1/(j+1.0))*(X0[i]);
            XX[i]=X[j][i];
        }
        while(cons(XX)==0)                                      /* 如果Xji不可行,重新生成它 */
        {
            for(i=0;i<n;i++)
            {
                X[j][i]=X0[i]+0.5*(X[j][i]-X0[i]);
                XX[i]=X[j][i];                                 /* 更新XX */
            }
        }
    }
}
double *Complex()
{
    double EE,Xc[n],Xh[n],Xg[n],Xl[n],Fh,Fg,Fl,Xr[n];
     double *prXl;
    int h,g,l;
    bou();
    produce(a,b);
    EE=E1+1;
    while(EE>E1)
    {
        for(i=0;i<n;i++)
        {
            Xc[i]=0;
            for(j=0;j<k;j++)
            {
                Xc[i]+=X[j][i];
            }
            Xc[i]=1/(k+0.0)*Xc[i];
        }
        for(j=0;j<k;j++)
        {
            for(i=0;i<n;i++)
            {
                XX[i]=X[j][i];
            }
            FF[j]=F(XX);
        }
        Fh=FF[0];
        Fg=FF[0];
        Fl=FF[0];
        h=0;
        g=0;
        l=0;
        for(j=0;j<k;j++)
        {
            if(FF[j]>Fh)
            {
                Fh=FF[j];
                h=j;
            }                                                    /* 最大点Xh */
            if(FF[j]<Fl)
            {
                Fl=FF[j];
                l=j;
            }                                                    /* 最小点Xl */
        }
        for(j=0;j<k;j++)                                         /* 第二最大点Xg */
            if((FF[j]>Fg)&&(j!=h))
            {
                Fg=FF[j];
                g=i;
            }
            for(i=0;i<n;i++)
            {
                Xh[i]=X[h][i];
                Xg[i]=X[g][i];
                Xl[i]=X[l][i];
            }
            EE=0;
            for(j=0;j<k;j++)
            {
                EE+=pow((FF[j]-F(Xc)),2);
            }
            EE=pow((1/(k+0.0)*EE),0.5);
            if(EE<=E1)
            {
                printf("\nF(Xmin)=%f\n",F(Xl)); 
                prXl=&X[1][0];
                break;
            }                                                   /* 结束搜寻和返回 */
            for(i=0;i<n;i++)
            {
                Xc[i]=0;
                for(j=0;j<k;j++)
                {
                    if(j!=h)
                        Xc[i]+=X[j][i];
                }
                Xc[i]=1/(k-1.0)*Xc[i];
            }
            if(cons(Xc)==1)                                     /* 若Xc可行 */
            {
                while(cons(Xc)==1)
                {
                    for(i=0;i<n;i++)
                    {
                        Xr[i]=Xc[i]+af*(Xc[i]-Xh[i]);
                    }
                    if(cons(Xr)==1)
                    {
                        if(F(Xr)>=F(Xh))
                        {
                            if(af<=ep)
                            {
                                for(i=0;i<n;i++)
                                {
                                    Xh[i]=Xg[i];               /* 将Xh替换成Xg */
                                }
                            }
                            else
                                af=1/2.0*af;
                        }
                        else
                        {
                            for(i=0;i<n;i++)
                            {
                                X[h][i]=Xr[i];                /* 将X[h][i]替换成Xr */
                            }
                            break;
                        }
                    }
                    else af=1/2.0*af;
                }
            }
            else
            {
                for(i=0;i<n;i++)
                {
                    a[i]=Xl[i];
                    b[i]=Xc[i];
                }
                produce(a,b);
            }
            }
            return prXl;
}
void mian()
{
    int i;
    double *pr;
    pr=complex();
    printf("\n");
    for(i=0;i<n;i++)
    {
        printf("X[%d]=%f\n",i,*(pr+i));
    }
}


下面是出现的错误:

--------------------Configuration: 1 - Win32 Debug--------------------
Linking...
1.obj : error LNK2001: unresolved external symbol __complex
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/1.exe : fatal error LNK1120: 2 unresolved externals
执行 link.exe 时出错.

1.exe - 1 error(s), 0 warning(s)

   


回复列表 (共1个回复)

沙发

void mian()
{
    int i;
    double *pr;
    pr=complex();
    printf("\n");
    for(i=0;i<n;i++)
    {
        printf("X[%d]=%f\n",i,*(pr+i));
    }
}

double *Complex()


main != mian
Complex != complex 


手误?怎么两处都能敲的有问题呢

我来回复

您尚未登录,请登录后再回复。点此登录或注册