Численные методы решения прикладных задач - page 251

251
Pp = P + h / 2 * z
zp = z + h / 2 * Fz(t, P, z)
t1 = t + h
P1 = P + h * zp
z1 = z + h * Fz(tp, Pp, zp)
t = t1
P = P1
z = z1
ActiveSheet.Cells(8 + i, 7).Value = t
ActiveSheet.Cells(8 + i, 8).Value = P
ActiveSheet.Cells(8 + i, 9).Value = z
Next i
End Sub
Решение в Microsoft Visual Studio
Код программы С++ при
n
=3
:
// pr1 ODU ekonom.cpp: определяет точку входа для консольного приложения.
//
#include
"stdafx.h"
#include
<iostream>
#include
<iomanip>
usingnamespace
std;
double
a=0, b=3, n=3, 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;
cout<<
"metod Eilera prostoi:"
<<endl;
cout<<setw(5)<<
"t"
<<setw(7)<<
"p"
<<setw(7)<<
"z"
<<endl;
cout<<setw(5)<<t0<<setw(7)<<p0<<setw(7)<<z0<<endl;
for
(i=0; i<n; i=i+1){
t=t0+h;
p=p0+h*z0;
z=z0+h*fz(t0,p0,z0);
cout<<setw(5)<<t<<setw(7)<<p<<setw(7)<<z<<endl;
t0=t; p0=p; z0=z;
}
}
void
eiler_usred(){
double
f1,f2,pv,zv;
double
t0=a, p0=4, z0=1;
cout<<
"metod Eilera s usredneniem:"
<<endl;
cout<<setw(5)<<
"t"
<<setw(7)<<
"p"
<<setw(7)<<
"z"
<<endl;
cout<<setw(5)<<t0<<setw(7)<<p0<<setw(7)<<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;
I...,241,242,243,244,245,246,247,248,249,250 252,253,254,255,256,257,258,259,260,261,...284
Powered by FlippingBook