Скачиваний:
13
Добавлен:
01.05.2014
Размер:
9.71 Кб
Скачать
// 5laba.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "5laba.h"
#include "5labaDlg.h"
#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMy5labaApp

BEGIN_MESSAGE_MAP(CMy5labaApp, CWinApp)
	//{{AFX_MSG_MAP(CMy5labaApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy5labaApp construction

CMy5labaApp::CMy5labaApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMy5labaApp object

CMy5labaApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMy5labaApp initialization

BOOL CMy5labaApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	CMy5labaDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

double tochka::Norma()
 {
	 return sqrt(x*x + y*y + v*v + w*w);
 };

 tochka plus (tochka a,tochka b)
 {
	tochka d;	
	d.x=a.x+b.x;
	d.y=a.y+b.y;
	d.z=a.z+b.z;
	d.v=a.v+b.v;
	d.w=a.w+b.w;
	return d;
 };

 tochka mult (tochka a,double al)
 {
	tochka d;
	d.x=a.x*al;
	d.y=a.y*al;
	d.z=a.z*al;
	d.v=a.v*al;
	d.w=a.w*al;
	return d;
 };


 double func (double al,tochka x, tochka p,int index)
{
 double r;
 switch (index)
 {
	case 0: r=3*pow((x.x+al*p.x)-4,2)+5*pow((x.y+al*p.y)+3,2)+7*pow(2*(x.z+al*p.z)+1,2);break;
	case 1: r=4*pow((x.x+al*p.x)-5,2)+pow((x.y+al*p.y)-6,2);break;
	case 2: r=8*(x.x+al*p.x)*(x.x+al*p.x)+5*(x.y+al*p.y)*(x.y+al*p.y)+4*(x.x+al*p.x)*(x.y+al*p.y);break;
 

 
 }
 return r;
};


 double a_def(double al,tochka x, tochka p,int index)
 {
 double y1;
	 switch (index)
 {
	case 0: y1=p.x*a_def3_1(al,x,p)+p.y*a_def3_2(al,x,p)+p.z*a_def3_3(al,x,p);break;
	case 1: y1=p.x*a_def2_1(al,x,p)+p.y*a_def2_2(al,x,p);break;
	case 2: y1=p.x*a_def1_1(al,x,p)+p.y*a_def1_2(al,x,p);break;

 }
 return y1;
}
 
double a_def1_1 (double al,tochka x, tochka p)
{
 double r;
 r=16*(x.x+al*p.x)+4*(x.y+al*p.y);
 return r;
};

double a_def1_2 (double al,tochka x, tochka p)
{
 double r;
 r=10*(x.y+al*p.y)+4*(x.x+al*p.x);
 return r;
};

double a_def2_1 (double al,tochka x, tochka p)
{
 double r;
 r=8*(x.x+al*p.x)-40;
 return r;
};

double a_def2_2 (double al,tochka x, tochka p)
{
 double r;
 r=2*(x.y+al*p.y)-12;
 return r;
};

double a_def3_1 (double al,tochka x, tochka p)
{
 double r;
 r=6*(x.x+al*p.x)-24;
 return r;
};

double a_def3_2 (double al,tochka x, tochka p)
{
 double r;
 r=10*(x.y+al*p.y)+30;
 return r;
};

double a_def3_3 (double al,tochka x, tochka p)
{
 double r;
 r=56*(x.z+al*p.z)+28;
 return r;
};

double c_def(double al,tochka x, tochka p,int index,double e)
 {
 double y1;
	switch (index)
 {
	case 2: y1=p.x*c_def1_1(al,x,p,e)+p.y*c_def1_2(al,x,p,e);break;

	case 1: y1=p.x*c_def2_1(al,x,p,e)+p.y*c_def2_2(al,x,p,e);break;

	case 0: y1=p.x*c_def3_1(al,x,p,e)+p.y*c_def3_2(al,x,p,e)+p.z*c_def3_3(al,x,p,e);break;
	}
 return y1;
};


double c_defall(double al,tochka x, tochka p, double e,int NumOfComp,int function)
{
double r;
tochka d; 
d=x;
switch(NumOfComp)
{
	
	case 1: d.x+=e; 
	case 2: d.y+=e; 
	case 3: d.z+=e; 
	case 4: d.v+=e; 
	case 5: d.w+=e; 
}
 r=(func(al,d,p,function)-func(al,x,p,function))/(e);
return r;
};


double c_def1_1 (double al,tochka x, tochka p, double e)
{
 double r;
 tochka d;
 d=x;
 d.x+=e;
 r=(func(al,d,p,2)-func(al,x,p,2))/(e);
  return r;
};

double c_def1_2 (double al,tochka x, tochka p,double e)
{
 double r;
 tochka d;
 d=x;
 d.y+=e;
 r=(func(al,d,p,2)-func(al,x,p,2))/(e);
 return r;
};

double alfa1 (tochka& x, tochka& h)
{
 return -(16*x.x*h.x+4*x.x*h.y+4*x.y*h.x+10*x.y*h.y)/(16*h.x*h.x+8*h.x*h.y+10*h.y*h.y);

};
//22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222//




double c_def2_1 (double al,tochka x, tochka p, double e)
{
 double r;
 tochka d;
 d=x;
 d.x+=e;
 r=(func(al,d,p,1)-func(al,x,p,1))/(e);
  return r;
};

double c_def2_2 (double al,tochka x, tochka p,double e)
{
 double r;
 tochka d;
 d=x;
 d.y+=e;
 r=(func(al,d,p,1)-func(al,x,p,1))/(e);
 return r;
};

double alfa2 (tochka& x, tochka& h)
{
	return -(4*x.x*h.x+x.y*h.y-2*(3*h.y+10*h.x))/(h.y*h.y+4*h.x*h.x);
};

//33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333//

double c_def3_1 (double al,tochka x, tochka p, double e)
{
 double r;
 tochka d;
 d=x;
 d.x+=e;
 r=(func(al,d,p,0)-func(al,x,p,0))/(e);
 return r;
};

double c_def3_2 (double al,tochka x, tochka p,double e)
{
 double r;
 tochka d;
 d=x;
 d.y+=e;
 r=(func(al,d,p,0)-func(al,x,p,0))/(e);
 return r;
};

double c_def3_3 (double al,tochka x, tochka p,double e)
{
 double r;
 tochka d;
 d=x;
 d.z+=e;
 r=(func(al,d,p,0)-func(al,x,p,0))/(e);
 return r;
};

double alfa3 (tochka& x, tochka& h)
{
 return -(6*x.x*h.x-24*h.x+10*x.y*h.y+30*h.y+56*x.z*h.z+28*h.z)/(6*h.x*h.x+10*h.y*h.y+56*h.z*h.z);

	//return -(16*x.x*h.x+4*x.x*h.y+4*x.y*h.x+10*x.y*h.y)/(16*h.x*h.x+8*h.x*h.y+10*h.y*h.y);
};
///////////////////////////////////////////////////////////////////////////////////////
double def1 (double al,tochka x, tochka p, double e, int m, int f)
{
double r;
	if ( 1 == m )
 {
	switch (f)
	{
		case 2:r=c_def1_1(al,x,p,e);break;
		case 1:r=c_def2_1(al,x,p,e);break;
		case 0:r=c_def3_1(al,x,p,e);break;
		default: AfxMessageBox("Error1");break;
	};
 }
 else
 {
	switch (f)
	{	
		case 2:r=a_def1_1(al,x,p);break;
		case 1:r=a_def2_1(al,x,p);break;
		case 0:r=a_def3_1(al,x,p);break;
		default: AfxMessageBox("Error1");break;
	};
};
 return r;
};

double def2 (double al,tochka x, tochka p, double e, int m, int f)
{
double r;
	if ( 1 == m )
 {
	switch (f)
	{
		case 2:r=c_def1_2(al,x,p,e);break;
		case 1:r=c_def2_2(al,x,p,e);break;
		case 0:r=c_def3_2(al,x,p,e);break;
		default: AfxMessageBox("Error2");break;
	};
 }
 else
 {
	switch (f)
	{	
		case 2:r=a_def1_2(al,x,p);break;
		case 1:r=a_def2_2(al,x,p);break;
		case 0:r=a_def3_2(al,x,p);break;
		default: AfxMessageBox("Error2");break;
	};
};
 return r;
};

double def3 (double al,tochka x, tochka p, double e, int m, int f)
{
double r;
	if (1 == m )
 {
	switch (f)
	{
		case 2:r=0;break;
		case 1:r=0;break;
		case 0:r=c_def3_3(al,x,p,e);break;
		default: AfxMessageBox("Error3");break;
	};
 }
 else
 {
	switch (f)
	{	
		case 2:r=0;break;
		case 1:r=0;break;
		case 0:r=a_def3_3(al,x,p);break;
		default: AfxMessageBox("Error3");break;
	};
};
 return r;
};

double def4 (double al,tochka x, tochka p, double e, int m, int f)
{
double r;
	if (1 == m)
 {
	switch (f)
	{
		case 2:r=0;break;
		case 1:r=0;break;
		case 0:r=0;break;
		default: AfxMessageBox("Error4");break;
	};
 }
 else
 {
	switch (f)
	{	
		case 2:r=0;break;
		case 1:r=0;break;
		case 0:r=0;break;
		default: AfxMessageBox("Error4");break;
	};
};
 return r;
};

double def5 (double al,tochka x, tochka p, double e, int m, int f)
{
double r;
	if (1 == m)
 {
	switch (f)
	{
		case 2:r=0;break;
		case 1:r=0;break;
		case 0:r=0;break;
		default: AfxMessageBox("Error4");break;
	};
 }
 else
 {
	switch (f)
	{	
		case 2:r=0;break;
		case 1:r=0;break;
		case 0:r=0;break;
		default: AfxMessageBox("Error4");break;
	};
};
 return r;
};


void sven (double &a, double &b, double al, tochka x, tochka p, int index, double e )
{
 double h=0.001;
 //cout<<"vvedite nahalnoe znachenie"<<endl;
 //cin>>x0;

 if (func(al+h,x,p,index)>func(al,x,p,index))
 {
 h=-h;
 };
 while (func(al+h,x,p,index)<func(al,x,p,index))
 {
 al=al+h;
 h=2*h;
 }
 a=al;
 b=al-0.75*h;
 if (b<a)
 {
  h=a;a=b;b=h;
 }
 //cout<<a<<" "<<b<<endl;
};

double dikh (tochka x, tochka p,int index,double e)
{
 double a,b,al=0;
 sven(a,b,al,x,p,index,e);
 while ((a-b)*(a-b)>e*e)
 {
  if (func(a,x,p,index)<func(b,x,p,index))
  {
  b=(a+b)/2;
  }
  else
  {
  a=(a+b)/2;
  }
  
 }
return (a+b)/2;
}


double alfa (tochka& x, tochka& p, int f)
{
double e=0.01;
double r;
	switch (f)
	{
		case 2:r=dikh(x,p,2,e);break;
			   //r=alfa1(x,p);break;
		case 1:r=dikh(x,p,1,e);break;
			  // r=alfa2(x,p);break;
		
		case 0:r=dikh(x,p,0,e);break;
			   //r=alfa3(x,p);break;
		
		default: AfxMessageBox("Error1");break;
	};
  return r;
};





Соседние файлы в папке all