Лабораторная работа №5.
#include<conio.h>
#include<iostream.h>
#include"define01.h"
int AprLine(int n, Vector X, Vector Y,
double& A0, double& A1, double& S);
void main()
{
Vector X,Y;
int n,i;
double S,A0,A1;
clrscr();
n=4;
X[1]=0.5; X[2]=1; X[3]=2; X[4]=3;
Y[1]=0.5; Y[2]=1; Y[3]=2; Y[4]=4;
for(i=1;i<=n;i++)
{
cout<<"X["<<i<<"]="<<X[i]<<" Y["<<i<<"]="<<Y[i]<<endl;
}
AprLine(n,X,Y,A0,A1,S);
cout<<"S="<<S<<endl;
cout<<"A0="<<A0<<endl;
cout<<"A1="<<A1<<endl;
getch();
}
Результат.
Задание №3.
#include<conio.h>
#include<iostream.h>
#include"define01.h"
int AprPoly(int n, Vector X, Vector Y, int m, Vector A, double& S);
void main()
{
Vector X, Y, A;
int n, i, m;
double S;
clrscr();
n = 5;
m = 3;
X[1] = 0.5; X[2] = 1.0; X[3] = 2.0; X[4] = 3.0; X[5] = 3.5;
Y[1] = 0.5; Y[2] = 1.0; Y[3] = 2.0; Y[4] = 3.0; Y[5] = 0.5;
for(i=1; i<=n; i++)
{
cout << "X[" << i << "]=" << X[i] << " Y[" << i << "]=" << Y[i] << "\n";
}
cout << "\n\n";
AprPoly(n, X, Y, m, A, S);
cout << "S=" << S << endl << endl;
for(i=0; i<=m; i++)
{
cout << "A[" << i << "]=" << A[i] << endl;
}
getch();
}
Лабораторная работа №6.
Задание №2.
Управляющая программа.
#include <iostream.h>
#include <conio.h>
double funame(double x);
double proiz_ar(double(*Fname)(double x),double x,double dx);
void main()
{
double pr, x, dx;
x = 2;
dx=0.0001;
pr = proiz_ar(funame, x, dx);
clrscr();
cout << "1-я производная: " << pr << endl;
getch();
}
Функции.
function.cpp
double funame(double x)
{
double y;
y=x*x*x*x;
return y;
}
proizvod.cpp
#include <iostream.h>
#include <conio.h>
double proiz_ar(double(*Fname)(double x),double x,double dx)
{
double dy;
dy=( Fname(x+dx)-Fname(x-dx) )/(2*dx);
return dy;
}
Задание №5.
Функция.
function.cpp
#include<iostream.h>
double function(double x)
{
double y;
y = 3*x*x;
return y;
}
Управляющие программы.
gauss.cpp
#include<iostream.h>
#include<conio.h>
double SdxGauss10(double(*FuncName)(double x), double a, double b);
double function(double x);
void main()
{
double a, b, Gauss;
clrscr();
a = -5;
b = 10;
Gauss = SdxGauss10(function, a, b);
cout << Gauss << endl;
getch();
}
spolinom.cpp
#include<iostream.h>
#include<conio.h>
#include"define01.h"
double SdxPolynom(int n, Vector A, double a, double b);
void main()
{
int n;
double a, b, Poly;
Vector A;
clrscr();
n = 3; a = -2; b = 4;
A[0] = 1; A[1] = 2; A[2] = -1; A[3] = 4;
Poly = SdxPolynom(n, A, a, b);
cout << "SdxPolynom = " << Poly << endl;
getch();
}
sdxspl.cpp
#include<iostream.h>
#include<conio.h>
#include"define01.h"
double SdxSpline(int n, Vector X,
Vector A, Vector B, Vector C, Vector D);
void main()
{
clrscr();
Vector X, A, B, C, D;
double Spline;
int n;
n = 4;
X[0] = 1; X[1] = 0; X[2] = 0; X[3] = 0; X[4] = 3;
A[1] = 1; A[2] = 0; A[3] = 4; A[4] = 1;
B[1] = 3; B[2] = 1; B[3] = 2; B[4] = 4;
C[1] = 3; C[2] = 2; C[3] = 6; C[4] = 3;
D[1] = 4; D[2] = 3; D[3] = 7; D[4] = 1;
Spline = SdxSpline(n, X, A, B, C, D);
cout << "SdxSpline = " << Spline << cout;
getch();
}
simps10.cpp
#include<iostream.h>
#include<conio.h>
int SdxSimpsEps(double(*FuncName)(double x),
double a, double b, double eps,
int limit, int KeyDemo, double& Sdx, int& Nckl);
double function(double x);
void main()
{
int Nckl, KD, limit, Err;
double a, b, Sdx, eps;
clrscr();
a = -5;
b = 10;
KD = 1;
eps = 0.0001;
limit = 20;
Err = SdxSimpsEps(function, a, b, eps, limit, KD, Sdx, Nckl);
cout << endl << endl;
cout << "Sdx = " << Sdx << endl;
cout << "Nckl = " << Nckl << endl;
cout << "Err = " << Err << endl;
getch();
}
simpson.cpp
#include<iostream.h>
#include<conio.h>
double SdxSimps(double(*FuncName)(double x), double a, double b, int n);
double function(double x);
void main()
{
double a, b, Simpson;
int n;
clrscr();
n = 20;
a = -5;
b = 10;
Simpson = SdxSimps(function, a, b, n);
cout << Simpson << endl;
getch();
}
simstab.cpp
#include<iostream.h>
#include<conio.h>
#include"define01.h"
double SdxSimpsTab(int n, Vector X, Vector F);
void main()
{
int n;
Vector X, F;
double SimpsTab;
clrscr();
n = 5;
X[1] = 1; X[2] = 0; X[3] = 0; X[4] = 0; X[5] = 6;
F[1] = 2; F[2] = 1; F[3] = 5; F[4] = 3; F[5] = 7;
SimpsTab = SdxSimpsTab(n, X, F);
cout << "SdxSimpsTab = " << SimpsTab << endl;
getch();
}
Задание №7.
Управляющая программа.
erf.cpp
#include <iostream.h>
#include <conio.h>
#include "define01.h"
double funame(double x);
double integ_ar(double(*Fname)(double x), double a, int n, Vector In);
void Write2Vec(int n1, int n2, Vector X, Vector Y,
string FileName=STRING0, string Remark=STRING0);
void main()
{
int a, n, i, n1, n2;
double in, k;
Vector In, B;
a = 0;
n = 10;
k = 0;
n1 = 1;
n2 = 10;
in = integ_ar(funame, a, n, In);
clrscr();
for(i=1; i<in; i++)
{
cout << "Значение Z=" << k << " функция равена: " << In[i] << endl;
k = k + 0.2;
B[i] = k;
}
getch();
Write2Vec(n1, n2, In, B);
}
Функции.
funname.cpp
#include <math.h>
double funame(double x)
{
double y;
y=(2/sqrt(3.14))*exp(-(x*x));
return y;
}
integral.cpp
#include <iostream.h>
#include "define01.h"
double integ_ar(double(*Fname)(double x), double a, int n, Vector In)
{
int i;
double h, S1, S2, k, j;
h = 0;
for(k=0, j=1; k<=2; k=k+0.2, j++)
{
h = (k - a)/n;
for(i=1, S1=0.0; i<=(n/2-1); i++)
S1 += Fname(a+2*i*h);
for(i=1, S2=0.0; i<=(n/2); i++)
S2 += Fname(a+(2*i-1)*h);
In[j] = (h/3)*(Fname(a) + Fname(k) + 2*S1 + 4*S2);
}
return j;
}
Задание №9.
Управляющая программа.
#include<iostream.h>
#include<conio.h>
double Simps2DRect(double(*FuncName)(double x, double y),
double ax, double bx, double ay, double by, int n);
double func(double x, double y);
void main()
{
int n;
double ax, bx, ay, by;
double Simps2D;
clrscr();
n = 10;
ax = -1; bx = 2; ay = 0; by = 4;
Simps2D = Simps2DRect(func, ax, bx, ay, by, n);
cout << "Simps2DRect = " << Simps2D << endl;
getch();
}
Функция.
#include<math.h>
double func(double x, double y)
{
return (x*y)/(pow(x,2) + pow(y,2));
}
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.