// SingerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Singer.h"
//////////////
#include "AnsDlg.h"
////////////////////////
#include "SingerDlg.h"
////////////////////////
#define r 0.57721566490
////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSingerDlg dialog
CSingerDlg::CSingerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSingerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSingerDlg)
m_edit_v1 = 0.0;
m_edit_v2 = 0.0;
m_edit_v3 = 0.0;
m_edit_x1 = 0.0;
m_edit_x2 = 0.0;
m_edit_x3 = 0.0;
m_edit_x4 = 0.0;
m_edit_x5 = 0.0;
m_check_neuman = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSingerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSingerDlg)
DDX_Text(pDX, IDC_EDIT_V1, m_edit_v1);
DDX_Text(pDX, IDC_EDIT_V2, m_edit_v2);
DDX_Text(pDX, IDC_EDIT_V3, m_edit_v3);
DDX_Text(pDX, IDC_EDIT_X1, m_edit_x1);
DDX_Text(pDX, IDC_EDIT_X2, m_edit_x2);
DDX_Text(pDX, IDC_EDIT_X3, m_edit_x3);
DDX_Text(pDX, IDC_EDIT_X4, m_edit_x4);
DDX_Text(pDX, IDC_EDIT_X5, m_edit_x5);
DDX_Check(pDX, IDC_CHECK_Neuman, m_check_neuman);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSingerDlg, CDialog)
//{{AFX_MSG_MAP(CSingerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BesselOk, OnBesselOk)
ON_BN_CLICKED(IDC_NeumanOk, OnNeumanOk)
ON_BN_CLICKED(IDC_Ans, OnAns)
ON_BN_CLICKED(IDC_CHECK_Neuman, OnCHECK_Neuman)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_BN_CLICKED(IDC_CLEAR2, OnClear2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSingerDlg message handlers
BOOL CSingerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CSingerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSingerDlg::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.SelectStockObject(WHITE_BRUSH);
dc.Rectangle(rect.left+162,rect.top,rect.right-1,rect.bottom-60);
dc.MoveTo(rect.right-1,rect.top);
dc.LineTo(rect.left+162,rect.top);
dc.LineTo(rect.left+162,rect.bottom-60);
dc.LineTo(rect.right-1,rect.bottom-60);
dc.LineTo(rect.right-1,rect.top);
dc.MoveTo(rect.left+162,(rect.top-rect.bottom+75)/2+rect.bottom-60);
dc.LineTo(rect.right-1,(rect.top-rect.bottom+75)/2+rect.bottom-60);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSingerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CSingerDlg::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::Create(IDD, pParentWnd);
}
double CSingerDlg::BesselJ(double v, double x)
{
double J,t2,t1;
int N=100000;
long int t;
t=v;
if(t==v)
{
J=0;
for(int k=0;k<N;k++)
{
J=J+cos(x*sin(k*pi/N)-v*k*pi/N)*pi/N;
}
J=J/pi;
}else
{
J=exp(v*log(x/2))/R(v+1);
t2=J;
for(int k=1;k<N;k++)
{
t1=-(x/2)*(x/2)/k/(v+k);
t2=t2*t1;
J=J+t2;
};
};
return J;
}
double CSingerDlg::R(double z)
{
long int N1=100,N2=N1+100;
if(R_T(N1,z)==0) //极点
{
cout<<"error"<<endl;
};
while(((R_T(N1,z)-R_T(N2,z))/R_T(N1,z)>err)||((R_T(N1,z)-R_T(N2,z))/R_T(N1,z)<-err))
{
N1=N1+100;
N2=N1+100;
}
return R_T(N2,z);
}
double CSingerDlg::R_T(long N, double z)
{
double k=0;
double dt=0.01;
double T=0;
if(z>0)
{
do
{
T=T+(1/exp(k+dt))*exp((z-1)*log(k+dt))*dt;
k=k+dt;
}
while(k<N);
}else if(z<0)
{
T=R_T(N,z+1)/z;
}
return T;
}
void CSingerDlg::OnBesselOk()
{
// TODO: Add your control notification handler code here
CDC *pDC;
pDC=GetDC();
////////////////////
CRect rect;
GetClientRect(&rect);
//////////////////
UpdateData(true);
v=m_edit_v1;
x1=m_edit_x1;
x2=m_edit_x2;
//////////////////
double x0=rect.left+162,y0=(rect.top-rect.bottom+75)/2+rect.bottom-60;
pDC->MoveTo(x0,BesselJ(v,x1)*(rect.top-rect.bottom+75)/2);
double delta=0.2,x=0,y=0;
do
{
y=BesselJ(v,x1+x)*(rect.top-rect.bottom+75)/2;
if((x1-x2)>=0)
{
MessageBox("请输入计算范围!");
break;
}else pDC->LineTo(x0+x/(x2-x1)*(rect.right-rect.left-170),y+y0);
x=x+delta;
}while(x<=x2);
}
void CSingerDlg::OnNeumanOk()
{
// TODO: Add your control notification handler code here
CDC *pDC;
pDC=GetDC();
////////////////////
CRect rect;
GetClientRect(&rect);
// pDC->SelectStockObject(WHITE_PEN);
//////////////////
UpdateData(true);
v=m_edit_v2;
x1=m_edit_x3;
x2=m_edit_x4;
//////////////////
double x0=rect.left+162,y0=(rect.top-rect.bottom+75)/2+rect.bottom-60;
pDC->MoveTo(x0,BesselY(v,x1)*(rect.top-rect.bottom+75)/2);
if(BesselY(v,x1)*(rect.top-rect.bottom+75)/2<rect.bottom-60) pDC->MoveTo(x0,rect.bottom-60);
double delta=0.05,x=0,y=0; ////调节delta可以调整图形精度
do
{
y=BesselY(v,x+x1)*(rect.top-rect.bottom+75)/4;//2
if((x1-x2)>=0)
{
MessageBox("请重新输入计算范围(x1<x2)!");
}else
pDC->LineTo(x0+x/(x2-x1)*(rect.right-rect.left-170),y+y0);
x=x+delta;
}while(x<x2);
}
void CSingerDlg::OnAns()
{
// TODO: Add your control notification handler code here
UpdateData(true);
CAnsDlg tem;
v=m_edit_v3;
x1=m_edit_x5;
double ans;
if(m_check_neuman)
ans=BesselY(v,x1);
else
ans=BesselJ(v,x1