Skip to content

Commit e4a4d2c

Browse files
Download code
Iteration method Eigenvalues
1 parent e6af909 commit e4a4d2c

15 files changed

+1228
-0
lines changed

Eigenvalues/Eigenvalues.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Eigenvalues.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
2+
//
3+
4+
#include <iostream>
5+
#include <string>
6+
#define SIZEMATRIX 3
7+
#define EPS 0.01 //0.0001 дает более точное приближение6,895
8+
using namespace std;
9+
10+
double* multimatrix_number(double** matrixA, double* matrix_vector);
11+
double* copyvector(double* vector1);
12+
int main()
13+
{
14+
setlocale(LC_ALL, "RU");
15+
double** matrixA = new double* [SIZEMATRIX];
16+
for (int i = 0; i < SIZEMATRIX; i++)
17+
matrixA[i] = new double[SIZEMATRIX] {};
18+
double* matrixX0 = new double[SIZEMATRIX];
19+
20+
cout << " Ввод осущствеляется по принципу: \nввод коэффициентов для определенной строки через пробел , "
21+
"\nих количество равно количеству указанных столбцов.\n "
22+
"(допускается: '+' ',' '-' '[0-9]' \n";
23+
cout << " Ввод матрицы А" << endl;
24+
for (int i = 0; i < SIZEMATRIX; i++)
25+
{
26+
for (int j = 0; j < SIZEMATRIX; j++)
27+
cin >> matrixA[i][j];// 5 1 2 / 1 4 1/ 2 1 3
28+
}
29+
cout << " Ввод вектора (начальное приближение)" << endl;
30+
for (int i = 0; i < SIZEMATRIX; i++)
31+
{
32+
cin >> matrixX0[i]; //1 1 1
33+
}
34+
35+
cout << "Output matrix" << endl;
36+
37+
for (int i = 0; i < SIZEMATRIX; i++)
38+
{
39+
for (int j = 0; j < SIZEMATRIX; j++)
40+
{
41+
cout << " " << matrixA[i][j] << " ";
42+
}
43+
cout << " = " << matrixX0[i] << endl;
44+
}
45+
double* matrixX1 = new double[SIZEMATRIX] {};
46+
matrixX1 = multimatrix_number(matrixA, matrixX0);
47+
cout << " Output matrixX1 :" << endl;
48+
for (int i = 0; i < SIZEMATRIX; i++)
49+
cout << matrixX1[i] << " ";
50+
51+
double* matrixL = new double[SIZEMATRIX] {};
52+
cout << " Output matrixL :" << endl;
53+
matrixL[1] = matrixX1[0] / matrixX0[0];
54+
cout << "лямбад0 = " << matrixL[1] << endl;
55+
56+
int k = 1;
57+
double* matrixX2 = new double[SIZEMATRIX] {};
58+
do
59+
{
60+
k++;
61+
matrixX2 = multimatrix_number(matrixA, matrixX1);
62+
cout << " Output matrixX2 :" << endl;
63+
for (int i = 0; i < SIZEMATRIX; i++)
64+
cout << matrixX2[i] << " ";
65+
66+
matrixL[k] = matrixX2[0] / matrixX1[0];
67+
cout << "лямбад" << k << " = " << matrixL[k] << endl;
68+
69+
matrixX1 = copyvector(matrixX2);
70+
71+
} while (abs(matrixL[k]-matrixL[k-1])>EPS);
72+
73+
cout << " Lambda = " << matrixL[k] << endl;
74+
75+
for (int i = 0; i < SIZEMATRIX; i++)
76+
delete[] matrixA[i];
77+
delete[] matrixA;
78+
delete[] matrixX0;
79+
delete[] matrixX2;
80+
//delete[] matrixL;
81+
}
82+
83+
double* multimatrix_number(double** matrixA, double* matrix_vector)
84+
{
85+
double* resultMatrix = new double[SIZEMATRIX]{};
86+
double sum = 0;
87+
for (int i = 0; i < SIZEMATRIX; i++)
88+
{
89+
for (int j = 0; j < SIZEMATRIX; j++)
90+
{
91+
resultMatrix[i] += matrixA[i][j] * matrix_vector[j];
92+
}
93+
}
94+
return resultMatrix;
95+
}
96+
97+
double* copyvector(double* vector1)
98+
{
99+
double* result_vector = new double[SIZEMATRIX] {};
100+
for (int i = 0; i < SIZEMATRIX; i++)
101+
result_vector[i] = vector1[i];
102+
return result_vector;
103+
}
104+
105+
106+
//k=2 58 38 40 l=7.25 0.75
107+
//k=3 408 250 274 l=7.034 0.116
108+
//k=4 2838 1682 1888 l=6.9559 0.078<e

Eigenvalues/Eigenvalues.sln

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}") = "Eigenvalues", "Eigenvalues.vcxproj", "{44382356-426D-4352-9667-E77A33A5078B}"
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+
{44382356-426D-4352-9667-E77A33A5078B}.Debug|x64.ActiveCfg = Debug|x64
17+
{44382356-426D-4352-9667-E77A33A5078B}.Debug|x64.Build.0 = Debug|x64
18+
{44382356-426D-4352-9667-E77A33A5078B}.Debug|x86.ActiveCfg = Debug|Win32
19+
{44382356-426D-4352-9667-E77A33A5078B}.Debug|x86.Build.0 = Debug|Win32
20+
{44382356-426D-4352-9667-E77A33A5078B}.Release|x64.ActiveCfg = Release|x64
21+
{44382356-426D-4352-9667-E77A33A5078B}.Release|x64.Build.0 = Release|x64
22+
{44382356-426D-4352-9667-E77A33A5078B}.Release|x86.ActiveCfg = Release|Win32
23+
{44382356-426D-4352-9667-E77A33A5078B}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {114D9D6E-1815-4B27-9CF9-FC3CDF61B4DA}
30+
EndGlobalSection
31+
EndGlobal

Eigenvalues/Eigenvalues.vcxproj

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>{44382356-426D-4352-9667-E77A33A5078B}</ProjectGuid>
24+
<Keyword>Win32Proj</Keyword>
25+
<RootNamespace>Eigenvalues</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="Eigenvalues.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="Eigenvalues.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)