Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
28
Добавлен:
01.05.2014
Размер:
143.87 Кб
Скачать

Исходный текст программы

/*

Файл: Lr_6.cpp

Автор: Усенко А.В.

Ред. 1.0 08.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 Fi(double); // x=Fi(x)

double Fi1(double); // Fi(x) derivative

double delta=0.1; // function calculating error

double M=2.5, // Max F1(x), x in [0.2;0.6]

m=2.2; // Min F1(x), x in [0.2;0.6]

ofstream f_out_1("out1.txt"), // Output data files

f_out_2("out2.txt"),

f_out_3("out3.txt");

double eps=0.1, // output data error

eps_theor=0; // Theoretical eps value

void main()

{

clrscr();

double func_val, // value of function

x, // value of root

_F,_Fi,_Fi1;

int n; // number of iterations

// file opening

if (f_out_1.fail() || f_out_2.fail() || f_out_3.fail())

{

cout<<"Impossible to open output file!"<<endl;

exit(1);

}

f_out_1.setf(ios::fixed);

f_out_1.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_1.precision(j);

f_out_1<<"Delta = "<<delta<<endl;

eps=0.1;

f_out_1<<"Eps\t\t"<<"X\t\t"<<"Fi(x)\t\t"<<"Fi'(x)\t\t"<<"F(x)\t\t"<<"N\t"<<"Eps_Theor\t"<<"Condit\n";

for (int i=1; i<=6; i++)

{

x=0.6;

f_out_1.precision(i);

x=ITER(x,eps,n,f_out_2);

_F=F(x); _Fi=Fi(x);_Fi1=Fi1(x);

f_out_1<<eps<<"\t"; if (i<6) {f_out_1<<"\t";};

f_out_1<<x<<"\t"; if (i<6) {f_out_1<<"\t";};

f_out_1.precision(j);

f_out_1<<_Fi<<"\t"; if ( (j<6) && !((j==5)&&(_Fi<0)) ) {f_out_1<<"\t";};

f_out_1<<_Fi1<<"\t"; if ( (j<6) && !((j==5)&&(_Fi1<0)) ) {f_out_1<<"\t";};

f_out_1<<_F<<"\t"; if ( (j<6) && !((j==5)&&(_F<0)) ) {f_out_1<<"\t";};

f_out_1<<n<<"\t";

eps_theor=delta/fabs(1/(1-Fi1(x)));

f_out_1.precision(6);

f_out_1<<eps_theor<<"\t";

if (eps>=eps_theor) {f_out_1<<"good\n";}

else {f_out_1<<"bad\n";}

eps = eps/10;

}

f_out_1<<endl<<endl;

delta = delta/10;

}

f_out_3.setf(ios::fixed);

f_out_3.setf(ios::showpoint);

f_out_3<<"X\t"<<"F(x)\t\tF'(x)\t\tFi(x)\t\tFi'(x)\n";

for (x=0;x<1;x=x+0.01)

{

f_out_3.precision(2);

f_out_3<<x<<"\t";

f_out_3.precision(9);

f_out_3<<F(x)<<"\t"<<F1(x)<<"\t"<<Fi(x)<<"\t"<<Fi1(x)<<endl;

}

f_out_1.close();

f_out_2.close();

f_out_3.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))/((1+x*x)*sqrt(1-4*x*x/pow((1+x*x),2))) + 2*x*exp(-x*x);

return Round(s,delta);

}

// x=Fi(x)

double Fi(double x)

{

extern double M,m,delta;

double s;

s=x-(2/(M+m))*F(x);

return Round(s,delta);

}

// First derivative of Fi(x)

double Fi1(double x)

{

extern double M,m,delta;

double s;

s=1-(2/(M+m))*F1(x);

return Round(s,delta);

}

Соседние файлы в папке Лабораторные работы 1 - 10