Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторные работы 1 - 10 / lr_3 / LR_3
.CPP/*
” ©«: Lr_3.cpp
Ђўв®а: “ᥪ® Ђ.‚.
ђҐ¤. 1.0 28.09.06
*/
#include <iostream.h>
#include <math.h>
#include <conio.h>
#include <fstream.h>
#include "methods.h"
// Global variables
double F(double); // Function
ofstream f_out; // Output data file
char out_path[11]="output.txt"; // Output file name
double delta=0.1, // function calculating error
eps=0.1; // output data error
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);
/* 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"<<"N\n";
for (int i=1; i<=6; i++)
{
f_out.precision(i);
x=BISECT(a,b,eps,n);
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) {f_out<<"\t";};
f_out<<n<<endl;
eps = eps/10;
}
f_out<<endl<<endl;
delta = delta/10;
}
f_out.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);
}