Skip to content

Commit 985aa52

Browse files
Download code
Cubic ODE: method Euler
1 parent 08c8694 commit 985aa52

14 files changed

+849
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include <iostream>
2+
#define SIZE 10
3+
using namespace std;
4+
5+
double function(double x, double y); // y'=3sin(2y)+x Начальное условие y(0)=2 на отрезке [0,1] h=0.1;
6+
double Runge_K(double x, double y, double h);
7+
8+
int main()
9+
{
10+
setlocale(LC_ALL, "RU");
11+
12+
double* nodeX = new double[SIZE+1]; //точки
13+
double* y = new double[SIZE+1]; // приближенное значений функций в этих точках
14+
double a = 0.0, b = 0.0;//отрезок
15+
cout << " Введите отрезок: начало : ";
16+
cin >> a;
17+
cout << " Введите отрезок: конец : ";
18+
cin >> b;
19+
cout << " Введите начальную точку x0 на отрезке: ";
20+
cin >> nodeX[0];
21+
cout << " Введите начальное условие : ";
22+
cin >> y[0];//nodeX[0];
23+
double h = 0.0; // если известны узлы то x[i-1]-x[i]
24+
int n = 0;
25+
cout << " Введите количество разбиений отрезка(целое): ";
26+
cin >> n;
27+
h = (b - a) / n;
28+
29+
int select = 0;
30+
cout << " Выбирете метод для вычисления ОДУ : \n";
31+
cout << " 1.Метод Эйлера.\n 2. Метод Рунге-Кутты 2 порядка(частный случай Эйлера)\n 3.Метод Рунге-Кутты 4 порядка\n";
32+
cin >> select;
33+
switch (select)
34+
{
35+
case 1:
36+
cout << " Вычисление ОДУ методом Эйлера: 3sin(2y)+x" << endl; // Неявная формула
37+
for (int i = 1; i <= n; i++)
38+
{
39+
nodeX[i] = nodeX[i - 1] + h; //a + i * h;
40+
y[i] = y[i - 1] + h * function(nodeX[i - 1], y[i - 1]);
41+
cout << " Итерация: " << i << " --> X[" << i << "] = " << nodeX[i] << "--> Y[" << i << "] = " << y[i] << endl;
42+
}
43+
break;
44+
case 2:
45+
cout << " Вычисление ОДУ методов Рунге-Кутты второго порядка\n(частный случай Эйлера) :3sin(2y)+x " << endl;
46+
for (int i = 1; i <= n; i++)
47+
{
48+
cout << "Прогноз : " << i << " : ";
49+
nodeX[i] = nodeX[i - 1] + h;
50+
y[i] = y[i - 1] + h * function(nodeX[i - 1], y[i - 1]);
51+
cout << " Y[" << i << "] = " << y[i] << endl;
52+
cout << "Коррекция : " << i << " ";
53+
y[i] = y[i - 1] + (h / 2) * (function(nodeX[i - 1], y[i - 1]) + function(nodeX[i], y[i]));
54+
cout << " Y[" << i << "] = " << y[i] << " --> X[" << i << "]" << nodeX[i] << endl;
55+
}
56+
break;
57+
case 3:
58+
cout << " Вычисление ОДУ методов Рунге-Кутты 4 порядка :3sin(2y)+x " << endl;
59+
for (int i = 1; i <= n; i++)
60+
{
61+
nodeX[i] = nodeX[i - 1] + h;
62+
y[i] = y[i - 1] + (h / 6.0) * (Runge_K(nodeX[i - 1], y[i - 1], h));
63+
cout << " Итерация: " << i << " --> X[" << i << "] = " << nodeX[i] << "--> Y[" << i << "] = " << y[i] << endl;
64+
}
65+
break;
66+
case 4:
67+
cout << " Вычисление ОДУ методом Адамса-Баншорта(экстраполяционный) 4 порядка : 3sin(2y)+x " << endl; //неявный
68+
break;
69+
case 5:
70+
cout << " Вычисление ОДУ методом Адамса-Мультона 2 порядка : 3sin(2y)+x " << endl; //явный
71+
72+
break;
73+
default:
74+
break;
75+
}
76+
77+
/*абс погр = max[i](abs(y[i] при h, -y[i] при h/2))/2^p-1*/
78+
delete[] nodeX;
79+
delete[] y;
80+
return 0;
81+
82+
}
83+
84+
double Runge_K(double x, double y,double h)
85+
{
86+
double k1 = function(x, y);
87+
double k2 = 2.0 * function(x + h / 2.0, y + (h / 2.0) * k1);
88+
double k3 = 2.0 * function(x + h / 2.0, y + (h / 2.0) *k2);
89+
double k4 = function(x + h, y + h * k3);
90+
return k1+ k2 + k3 + k4;
91+
}
92+
93+
double function(double x, double y)
94+
{
95+
return 3 * sin(2 * y) + x;
96+
}
97+
98+
//function y''+3xy'-2y=1.5; [0.5,1] y(0.5)=1, y'(0.5)=0.5 h=0.1
99+
//y'=z; y(0.5)=1, z(0.5)=0.5
100+
// z'=-3xz+2y+1.5
101+
/*
102+
double function(x,y,z)
103+
{
104+
return -3*x*z+2y+1.5;
105+
}
106+
107+
в main()
108+
{
109+
//ввод отрезка а,b
110+
//ввод х0 = a
111+
//ввод у0 =1
112+
//ввод z0 = 0.5
113+
//h = (b-a)/n
114+
for(int i=1;i<=n;i++)
115+
{
116+
x[i]=x[i-1]+h;
117+
y[i]=y[i-1]+h*function(x[i-1],y[i-1],z[i-1]);
118+
z[i]=z[i-1]+h*G(x[i-1],y[i-1],z[i-1]);
119+
}
120+
}
121+
122+
*/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28803.202
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "methodEulera", "methodEulera.vcxproj", "{174A6D89-D401-4F75-BFA1-0FBE899098B0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{174A6D89-D401-4F75-BFA1-0FBE899098B0}.Debug|x64.ActiveCfg = Debug|x64
17+
{174A6D89-D401-4F75-BFA1-0FBE899098B0}.Debug|x64.Build.0 = Debug|x64
18+
{174A6D89-D401-4F75-BFA1-0FBE899098B0}.Debug|x86.ActiveCfg = Debug|Win32
19+
{174A6D89-D401-4F75-BFA1-0FBE899098B0}.Debug|x86.Build.0 = Debug|Win32
20+
{174A6D89-D401-4F75-BFA1-0FBE899098B0}.Release|x64.ActiveCfg = Release|x64
21+
{174A6D89-D401-4F75-BFA1-0FBE899098B0}.Release|x64.Build.0 = Release|x64
22+
{174A6D89-D401-4F75-BFA1-0FBE899098B0}.Release|x86.ActiveCfg = Release|Win32
23+
{174A6D89-D401-4F75-BFA1-0FBE899098B0}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {4A1F8CB5-C78F-4A62-B81A-63B6CD48E87D}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<ProjectGuid>{174A6D89-D401-4F75-BFA1-0FBE899098B0}</ProjectGuid>
24+
<Keyword>Win32Proj</Keyword>
25+
<RootNamespace>methodEulera</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v142</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v142</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v142</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v142</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<LinkIncremental>true</LinkIncremental>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
77+
<LinkIncremental>true</LinkIncremental>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
80+
<LinkIncremental>false</LinkIncremental>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
83+
<LinkIncremental>false</LinkIncremental>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86+
<ClCompile>
87+
<PrecompiledHeader>
88+
</PrecompiledHeader>
89+
<WarningLevel>Level3</WarningLevel>
90+
<Optimization>Disabled</Optimization>
91+
<SDLCheck>true</SDLCheck>
92+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
93+
<ConformanceMode>true</ConformanceMode>
94+
</ClCompile>
95+
<Link>
96+
<SubSystem>Console</SubSystem>
97+
<GenerateDebugInformation>true</GenerateDebugInformation>
98+
</Link>
99+
</ItemDefinitionGroup>
100+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
101+
<ClCompile>
102+
<PrecompiledHeader>
103+
</PrecompiledHeader>
104+
<WarningLevel>Level3</WarningLevel>
105+
<Optimization>Disabled</Optimization>
106+
<SDLCheck>true</SDLCheck>
107+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108+
<ConformanceMode>true</ConformanceMode>
109+
</ClCompile>
110+
<Link>
111+
<SubSystem>Console</SubSystem>
112+
<GenerateDebugInformation>true</GenerateDebugInformation>
113+
</Link>
114+
</ItemDefinitionGroup>
115+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
116+
<ClCompile>
117+
<PrecompiledHeader>
118+
</PrecompiledHeader>
119+
<WarningLevel>Level3</WarningLevel>
120+
<Optimization>MaxSpeed</Optimization>
121+
<FunctionLevelLinking>true</FunctionLevelLinking>
122+
<IntrinsicFunctions>true</IntrinsicFunctions>
123+
<SDLCheck>true</SDLCheck>
124+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
125+
<ConformanceMode>true</ConformanceMode>
126+
</ClCompile>
127+
<Link>
128+
<SubSystem>Console</SubSystem>
129+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
130+
<OptimizeReferences>true</OptimizeReferences>
131+
<GenerateDebugInformation>true</GenerateDebugInformation>
132+
</Link>
133+
</ItemDefinitionGroup>
134+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
135+
<ClCompile>
136+
<PrecompiledHeader>
137+
</PrecompiledHeader>
138+
<WarningLevel>Level3</WarningLevel>
139+
<Optimization>MaxSpeed</Optimization>
140+
<FunctionLevelLinking>true</FunctionLevelLinking>
141+
<IntrinsicFunctions>true</IntrinsicFunctions>
142+
<SDLCheck>true</SDLCheck>
143+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
144+
<ConformanceMode>true</ConformanceMode>
145+
</ClCompile>
146+
<Link>
147+
<SubSystem>Console</SubSystem>
148+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
149+
<OptimizeReferences>true</OptimizeReferences>
150+
<GenerateDebugInformation>true</GenerateDebugInformation>
151+
</Link>
152+
</ItemDefinitionGroup>
153+
<ItemGroup>
154+
<ClCompile Include="methodEulera.cpp" />
155+
</ItemGroup>
156+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
157+
<ImportGroup Label="ExtensionTargets">
158+
</ImportGroup>
159+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Исходные файлы">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Файлы заголовков">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Файлы ресурсов">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="methodEulera.cpp">
19+
<Filter>Исходные файлы</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

0 commit comments

Comments
 (0)