253
// pr1 ODU ekonom.cpp: определяет точку входа для консольного приложения.
//
#include
"stdafx.h"
#include
<iostream>
#include
<iomanip>
#include
<fstream>
usingnamespace
std;
double
a=0, b=3, n=100, h=(b-a)/n;
double
t, p, z;
int
i;
double
fy(
double
z){
return
z;
}
double
fz(
double
t,
double
p,
double
z){
return
15.0-2.0*z-5.0*p;
}
void
eiler_prost(){
double
t0=a, p0=4, z0=1;
fstream file1;
file1.open(
"eiler_pr.xls"
, ios::out);
file1<<
"t"
<<
"\t"
<<
"p"
<<
"\t"
<<
"z"
<<endl;
file1<<t0<<
"\t"
<<p0<<
"\t"
<<z0<<endl;
for
(i=0; i<n; i=i+1){
t=t0+h;
p=p0+h*z0;
z=z0+h*fz(t0,p0,z0);
file1<<t<<
"\t"
<<p<<
"\t"
<<z<<endl;
t0=t; p0=p; z0=z;
}
file1.close();
}
void
eiler_usred(){
double
f1,f2,pv,zv;
double
t0=a, p0=4, z0=1;
fstream file2;
file2.open(
"eiler_usr.xls"
, ios::out);
file2<<
"t"
<<
"\t"
<<
"p"
<<
"\t"
<<
"z"
<<endl;
file2<<t0<<
"\t"
<<p0<<
"\t"
<<z0<<endl;
for
(i=0; i<n; i=i+1){
f1=fz(t0,p0,z0);
pv=p0+h*z0;
zv=z0+h*f1;
f2=fz(t0,pv,zv);
t=t0+h;
p=p0+h*(z0+zv)/2.0;
z=z0+h*(f1+f2)/2.0;
file2<<t<<
"\t"
<<p<<
"\t"
<<z<<endl;
t0=t; p0=p; z0=z;
}
file2.close();
}
void
eiler_centr(){
double
f1,f2,tv,pv,zv;
double
t0=a, p0=4, z0=1;
fstream file3;
file3.open(
"eiler_centr.xls"
, ios::out);
file3<<
"t"
<<
"\t"
<<
"p"
<<
"\t"
<<
"z"
<<endl;
file3<<t0<<
"\t"
<<p0<<
"\t"
<<z0<<endl;