📄 dialog4.cpp
字号:
// Dialog4.cpp : implementation file
//
#include "stdafx.h"
#include "neuro.h"
#include "Dialog4.h"
#include"math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialog4 dialog
CDialog4::CDialog4(CWnd* pParent /*=NULL*/)
: CDialog(CDialog4::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialog4)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDialog4::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialog4)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialog4, CDialog)
//{{AFX_MSG_MAP(CDialog4)
ON_BN_CLICKED(IDC_BUTTON1, Onplot)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialog4 message handlers
void CDialog4::Onplot()
{
Invalidate();
d1=(CEdit*)GetDlgItem(IDC_EDIT1);
d2=(CEdit*)GetDlgItem(IDC_EDIT2);
d3=(CEdit*)GetDlgItem(IDC_EDIT3);
d4=(CEdit*)GetDlgItem(IDC_EDIT4);
d5=(CEdit*)GetDlgItem(IDC_EDIT5);
d6=(CEdit*)GetDlgItem(IDC_EDIT6);
d7=(CEdit*)GetDlgItem(IDC_EDIT7);
d1->GetWindowText(sd1);
d2->GetWindowText(sd2);
d3->GetWindowText(sd3);
d4->GetWindowText(sd4);
d5->GetWindowText(sd5);
d6->GetWindowText(sd6);
d7->GetWindowText(sd7);
double a1=atof(sd1);
double a2=atof(sd2);
double a3=atof(sd3);
double a4=atof(sd4);
double a5=atof(sd5);
double a6=atof(sd6);
double a7=atof(sd7);
num13=a1*(1-exp(-1/a2));
num12=0;
num11=0;
den11=1;
den12=-exp(-1/a2);
den13=0;
double Y[200];
double T[200];
for(int h=0;h<200;h++)
{T[h]=h+1;}
double x[2]={0,0};
double y[10]={0,0,0,0,0,0,0,0,0,0};
double e[10]={0,0,0,0,0,0,0,0,0,0};
double u[10]={0,0,0,0,0,0,0,0,0,0};
double d[2]={20,20};
double w[2]={0.1,0.1};
int t;
double E;
double EC;
double Uf;
double delte;
double r=1;
double alfa=0.6;
for(t=0;t<200;t++)
{
e[0]=r-y[0];
delte=e[0]-e[1];
E=floor(a5*e[0]+0.5);
EC=floor(a6*delte+0.5);
Uf=alfa*floor(alfa*E+(1-alfa)*EC+0.5);
x[0]=Uf;x[1]=x[1]+a4*Uf;
for (int z=9;z>=1;z--)
{
u[z]=u[z-1];
y[z]=y[z-1];
e[z]=e[z-1];
}
double s=0;double ss=0;
for (int i=0;i<=1;i++)
{
s=s+w[i]*x[i];
ss=ss+fabs(w[i]);
}
if (ss==0)
{ss=0.001;}
u[0]=a4*s/ss;
y[0]=-den12*y[1]-den13*y[2]+num12*u[1]+num13*u[2];
for (int j=0;j<=1;j++)
{w[j]=w[j]+d[j]*(r-y[0])*x[j];
}
Y[t]=y[0];
}
CPaintDC dc(this); // device context for painting
CDC *pDC=GetDC();
//初始化坐标值
double data_x[200];
double data_y[200];
for(int j=0;j<200;j++)
{data_x[j]=T[j];
data_y[j]=Y[j];
}
//double initX[10]={1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0};
//double initY[10]={0.5,2.0,2.8,4.0,5.6,6.0,7.0,9.4,13.8,23.4};
//分别取得X和Y最大值,最小值
double maxX=data_x[0];
double minX=data_x[0];
double maxY=data_y[0];
double minY=data_y[0];
for(int i=0;i<200;i++)
{
if(data_x[i]>maxX)
maxX=data_x[i];
if(data_x[i]<minX)
minX=data_x[i];
if(data_y[i]>maxY)
maxY=data_y[i];
if(data_y[i]<minY)
minY=data_y[i];
}
//如果原点必须在X轴上,加上下面2行,否则注释掉
if(minX>0)
minX=0;
//如果原点必须在Y轴上,加上下面2行,否则注释掉
if(minY>0)
minY=0;
//确定图象显示大小
//确定坐标图四周预留的空白大小
int width=300;
int height=300;
//确定坐标图四周预留的空白大小
const int mytop=60;
const int mybottom=10;
const int myleft=50;
const int myright=10;
//确定X,Y轴每单位显示宽度
double intervalX=(width-myleft-myright)/(maxX-minX);
double intervalY=(height-mybottom-mytop)/(maxY-minY);
//绘制曲线。由于绘图坐标的Y轴是向下延升,所以这里每个点的Y值是用
//图象高度减去y值大小。
pDC->MoveTo(int(myleft+(data_x[0]-minX)*intervalX),int(height-(mybottom+(data_y[0]-minY)*intervalY)));
for(i=0;i<200;i++)
{
pDC->LineTo(int(myleft+(data_x[i]-minX)*intervalX),
int(height-(mybottom+(data_y[i]-minY)*intervalY)));
}
//绘制X,Y轴
//X轴从图形区域最左端到最右端
double bottomY=0;
double leftX=0;
//bottomY表示X轴的y值,leftX表示Y轴的x值
if(minY>0)
bottomY=minY;
if(minX>0)
leftX=minX;
pDC->MoveTo(int(myleft),int(height-(mybottom+(bottomY-minY)*intervalY)));
pDC->LineTo(int(width-myright),int(height-(mybottom+(bottomY-minY)*intervalY)));
//Y轴从图形区域最底端到最顶端
pDC->MoveTo(int(myleft+(leftX-minX)*intervalX),int(height-mybottom));
pDC->LineTo(int(myleft+(leftX-minX)*intervalX),int(mytop));
//确定显示刻度个数
const int count=5;const int count1=5;
//确定每个显示刻度之间的宽度
double spaceX=(width-myleft-myright)/count;
double spaceY=(height-mybottom-mytop)/count1;
//绘制刻度和刻度值
CString str;
//X轴
for(i=0;i<=count;i++)
{
str.Format("%.1f",minX+i*(maxX-minX+1)/count);
pDC->MoveTo(int(myleft+spaceX*i),int(height-(mybottom+(bottomY-minY)*intervalY)));
pDC->LineTo(int(myleft+spaceX*i),int(height-(mybottom+(bottomY-minY)*intervalY+5)));
pDC->TextOut(int(myleft+spaceX*i-10),
int(height-(mybottom+(bottomY-minY)*intervalY-5)),str);
}
//Y轴
for(i=0;i<=count1;i++)
{
str.Format("%.1f",minY+i*(maxY-minY)/count1);
pDC->MoveTo(int(myleft+(leftX-minX)*intervalX),int(height-(mybottom+spaceY*i)));
pDC->LineTo(int(myleft+(leftX-minX)*intervalX+5),int(height-(mybottom+spaceY*i)));
pDC->TextOut(int(myleft+(leftX-minX)*intervalX-50),
int(height-(mybottom+spaceY*i+8)),str);
}
//绘制X,Y轴的变量名
pDC->TextOut((width-myleft)/2,height-5,"t/min");
pDC->TextOut(10,height/2+10,"Basic Weight");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -