Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

vm_labs / lr_4 / LR_4

.CPP
Скачиваний:
5
Добавлен:
09.02.2015
Размер:
2.23 Кб
Скачать
/*
  ” ©«: Lr_4.cpp


  Ђўв®а: “ᥭЄ® Ђ.‚.
  ђҐ¤. 1.0  06.10.06
*/

#include <iostream.h>
#include <math.h>
#include <conio.h>
#include <fstream.h>
#include "methods.h"


// Global variables
double	F(double);	// Function
double	F1(double);	// Derivative
double	delta=0.1;	// function calculating error

ofstream	f_out, f_out_2("out2.txt");	// Output data file

char	out_path[11]="out1.txt";	// Output file name


double	eps=0.1,	// output data error
	eps_theor=0;	// Theoretical eps value

double	a=0,b=1;	// interval borders



void main()
{
 clrscr();

 double	func_val,	// value of function
	x;		// value of root
 int	n;		// number of iterations

 // file opening

 f_out.open(out_path);
 if (f_out.fail())
 {
	cout<<"Impossible to open output file!"<<endl;
	exit(1);
 }



 f_out.setf(ios::fixed);
 f_out.setf(ios::showpoint);

 f_out_2.setf(ios::fixed);
 f_out_2.setf(ios::showpoint);
 f_out_2.precision(9);

 /* Calculating & table printing */
 delta=0.1;
 for (int j=1; j<=6; j++)
 {
	f_out.precision(j);
	f_out<<"Delta = "<<delta<<endl;

	eps=0.1;
	f_out<<"Eps\t\t"<<"X\t\t"<<"F(x)\t\t"<<"F'(x)\t\t"<<"N\t"<<"Eps_Theor\t"<<"Condit\n";
	for (int i=1; i<=6; i++)
	{
		f_out.precision(i);
		x=HORDA(a,b,eps,n,f_out_2);
		f_out<<eps<<"\t"; if (i<6) {f_out<<"\t";};
		f_out<<x<<"\t";   if (i<6) {f_out<<"\t";};
		f_out.precision(j);
		f_out<<F(x)<<"\t"; if ( (j<6) && !((j==5)&&(F(x)<0)) ) {f_out<<"\t";};
		f_out<<F1(x)<<"\t"; if ( (j<6) && !((j==5)&&(F1(x)<0)) ) {f_out<<"\t";};
		f_out<<n<<"\t";
		eps_theor=delta/fabs(F1(x));
		f_out.precision(6);
		f_out<<eps_theor<<"\t";
		if (eps>=eps_theor) {f_out<<"good\n";}
		else	{f_out<<"bad\n";}

		eps = eps/10;
	}

	f_out<<endl<<endl;
	delta = delta/10;
 }


 f_out.close();
 f_out_2.close();

 cout<<"Program finished. Press <Enter>...";
 getch();
 return;
}

// Function definition
double	F(double x)
{
	extern double delta;
	double s;

	s = asin(2*x/(1+x*x))-exp(-x*x);
	return Round(s,delta);
}

// Derivative definition
double	F1(double x)
{
	double	s;

	s=(2-4*x*x)/((1+x*x)*sqrt(1-4*x*x/pow((1+x*x),2))) + 2*x*exp(-x*x);
	return Round(s,delta);
}


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