Commit 5f6e6d72 authored by Саидбаталов Дмитрий's avatar Саидбаталов Дмитрий
Browse files

Добавьте файлы проекта.

parent 00b2832b

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30621.155
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NM_Saidbatalov_LR5", "NM_Saidbatalov_LR5\NM_Saidbatalov_LR5.vcxproj", "{4585C8F4-9E57-4635-9D35-533B259EDFA5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4585C8F4-9E57-4635-9D35-533B259EDFA5}.Debug|x64.ActiveCfg = Debug|x64
{4585C8F4-9E57-4635-9D35-533B259EDFA5}.Debug|x64.Build.0 = Debug|x64
{4585C8F4-9E57-4635-9D35-533B259EDFA5}.Debug|x86.ActiveCfg = Debug|Win32
{4585C8F4-9E57-4635-9D35-533B259EDFA5}.Debug|x86.Build.0 = Debug|Win32
{4585C8F4-9E57-4635-9D35-533B259EDFA5}.Release|x64.ActiveCfg = Release|x64
{4585C8F4-9E57-4635-9D35-533B259EDFA5}.Release|x64.Build.0 = Release|x64
{4585C8F4-9E57-4635-9D35-533B259EDFA5}.Release|x86.ActiveCfg = Release|Win32
{4585C8F4-9E57-4635-9D35-533B259EDFA5}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5736620F-5D8C-4B63-9A66-2263CD5BE29F}
EndGlobalSection
EndGlobal
#include <iostream>
#include "SLAE.h"
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int N = 800;
int l = 23;
int L = 2 * l;
double eps = pow(10, -5);
double** A1 = genStripMatrix(N, l, 1.1);
double** A2 = genStripMatrix(N, l, 2);
double** A3 = genStripMatrix(N, l, 10);
/* cout << "A" << endl;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cout << A1[i][j] << "\t";
}
cout << endl;
}*/
double* x1 = genVector(N);
double* x2 = genVector(N);
double* x3 = genVector(N);
double* b1 = getB(A1, x1, N);
double* b2 = getB(A2, x3, N);
double* b3 = getB(A3, x3, N);
/*cout << endl << "x" << endl;
for (int i = 0; i < N; i++)
{
cout << x1[i] << endl;
}
cout << endl << "b" << endl;
for (int i = 0; i < N; i++)
{
cout << b1[i] << endl;
}*/
SLAE sl_1 = symmetrization(A1, b1, N, l);
SLAE sl_2 = symmetrization(A2, b2, N, l);
SLAE sl_3 = symmetrization(A3, b3, N, l);
/*cout << endl << "A*" << endl;
for (int i = 0; i < N; i++)
{
for (int j = 0; j <= 2 * l; j++)
{
cout << sl_1.A[i][j] << "\t";
}
cout << endl;
}*/
/*cout << endl << "b*" << endl;
for (int i = 0; i < N; i++)
{
cout << sl_1.b[i] << endl;
}*/
double* x_0_1 = new double[N];
double* x_0_2 = new double[N];
double* x_0_3 = new double[N];
auto x_dist = std::uniform_real_distribution<>(-1., 1.);
auto rng = std::default_random_engine();
for (int i = 0; i < N; i++)
{
x_0_1[i] = x_dist(rng);
x_0_2[i] = x_dist(rng);
x_0_3[i] = x_dist(rng);
}
double norm_1 = 0.;
double norm_2 = 0.;
double norm_3 = 0.;
double* solve_1;
double* solve_2;
double* solve_3;
solve_1 = Jacobi(sl_1, x_0_1, N, L, eps);
solve_2 = Jacobi(sl_2, x_0_2, N, L, eps);
solve_3 = Jacobi(sl_3, x_0_3, N, L, eps);
for (int h = 0; h < N; h++)
{
if (fabs(solve_1[h] - x1[h]) > norm_1)
norm_1 = fabs(solve_1[h] - x1[h]);
if (fabs(solve_2[h] - x2[h]) > norm_2)
norm_2 = fabs(solve_2[h] - x2[h]);
if (fabs(solve_3[h] - x3[h]) > norm_3)
norm_3 = fabs(solve_3[h] - x3[h]);
}
cout << "---------------------------------------------------------------" << endl;
cout << "Задача 2" << endl;
cout << "Решение СЛАУ 1 методом Якоби:" << endl;
cout << "Погрешность:" << norm_1 << endl;
cout << "Количество итераций:" << solve_1[N] << endl;
//////////////////////////////////////////////////////////
cout << endl << "Решение СЛАУ 2 методом Якоби:" << endl;
cout << "Погрешность:" << norm_2 << endl;
cout << "Количество итераций:" << solve_2[N] << endl;
///////////////////////////////////////////////////////////
cout << endl << "Решение СЛАУ 3 методом Якоби:" << endl;
cout << "Погрешность:" << norm_3 << endl;
cout << "Количество итераций:" << solve_3[N] << endl;
cout << "---------------------------------------------------------------" << endl;
norm_1 = 0.;
norm_2 = 0.;
norm_3 = 0.;
double w = 1.0;
solve_1 = SOR(sl_1, x_0_1, N, L, eps, w);
solve_2 = SOR(sl_2, x_0_2, N, L, eps, w);
solve_3 = SOR(sl_3, x_0_3, N, L, eps, w);
for (int h = 0; h < N; h++)
{
if (fabs(solve_1[h] - x1[h]) > norm_1)
norm_1 = fabs(solve_1[h] - x1[h]);
if (fabs(solve_2[h] - x2[h]) > norm_2)
norm_2 = fabs(solve_2[h] - x2[h]);
if (fabs(solve_3[h] - x3[h]) > norm_3)
norm_3 = fabs(solve_3[h] - x3[h]);
}
cout << "---------------------------------------------------------------" << endl;
cout << "Задача 3. w =" << w << endl;
cout << "Решение СЛАУ 1 методом SOR:" << endl;
cout << "Погрешность:" << norm_1 << endl;
cout << "Количество итераций:" << solve_1[N] << endl;
////////////////////////////////////////////////////////
cout << endl << "Решение СЛАУ 2 методом SOR:" << endl;
cout << "Погрешность:" << norm_2 << endl;
cout << "Количество итераций:" << solve_2[N] << endl;
/////////////////////////////////////////////////////////
cout << endl << "Решение СЛАУ 3 методом SOR:" << endl;
cout << "Погрешность:" << norm_3 << endl;
cout << "Количество итераций:" << solve_3[N] << endl;
cout << "---------------------------------------------------------------" << endl;
norm_1 = 0.;
norm_2 = 0.;
norm_3 = 0.;
solve_1 = CGM(sl_1, x_0_1, N, L, eps);
solve_2 = CGM(sl_2, x_0_2, N, L, eps);
solve_3 = CGM(sl_3, x_0_3, N, L, eps);
for (int h = 0; h < N; h++)
{
if (fabs(solve_1[h] - x1[h]) > norm_1)
norm_1 = fabs(solve_1[h] - x1[h]);
if (fabs(solve_2[h] - x2[h]) > norm_2)
norm_2 = fabs(solve_2[h] - x2[h]);
if (fabs(solve_3[h] - x3[h]) > norm_3)
norm_3 = fabs(solve_3[h] - x3[h]);
}
cout << "---------------------------------------------------------------" << endl;
cout << "Задача 4" << endl;
cout << "Решение СЛАУ 1 методом CGM:" << endl;
cout << "Погрешность:" << norm_1 << endl;
cout << "Количество итераций:" << solve_1[N] << endl;
////////////////////////////////////////////////////////
cout << endl << "Решение СЛАУ 2 методом CGM:" << endl;
cout << "Погрешность:" << norm_2 << endl;
cout << "Количество итераций:" << solve_2[N] << endl;
/////////////////////////////////////////////////////////
cout << endl << "Решение СЛАУ 3 методом CGM:" << endl;
cout << "Погрешность:" << norm_3 << endl;
cout << "Количество итераций:" << solve_3[N] << endl;
cout << "---------------------------------------------------------------" << endl;
norm_1 = 0.;
norm_2 = 0.;
norm_3 = 0.;
int m = 4;
//solve_1 = PCGM(sl_1, x_0_1, N, 2 * l, eps, m);
solve_2 = PCGM(sl_2, x_0_2, N, L, eps, m);
solve_3 = PCGM(sl_3, x_0_3, N, L, eps, m);
for (int h = 0; h < N; h++)
{
//if (fabs(solve_1[h] - x1[h]) > norm_1)
// norm_1 = fabs(solve_1[h] - x1[h]);
if (fabs(solve_2[h] - x2[h]) > norm_2)
norm_2 = fabs(solve_2[h] - x2[h]);
if (fabs(solve_3[h] - x3[h]) > norm_3)
norm_3 = fabs(solve_3[h] - x3[h]);
}
cout << "Количество шагов метода Якоби: m = " << m << endl;
//cout << "Решение СЛАУ 1 методом PCGM:" << endl;
//cout << "Погрешность:" << norm_1 << endl;
//cout << "Количество итераций:" << solve_1[N] << endl;
////////////////////////////////////////////////////////
cout << endl << "Решение СЛАУ 2 методом PCGM:" << endl;
cout << "Погрешность:" << norm_2 << endl;
cout << "Количество итераций:" << solve_2[N] << endl;
/////////////////////////////////////////////////////////
cout << endl << "Решение СЛАУ 3 методом PCGM:" << endl;
cout << "Погрешность:" << norm_3 << endl;
cout << "Количество итераций:" << solve_3[N] << endl;
cout << "---------------------------------------------------------------" << endl;
for (int i = 0; i < N; i++)
{
delete[] A1[i];
delete[] A2[i];
delete[] A3[i];
delete[] sl_1.A[i];
delete[] sl_2.A[i];
delete[] sl_3.A[i];
}
delete[] A1;
delete[] A2;
delete[] A3;
delete[] sl_1.A;
delete[] sl_2.A;
delete[] sl_3.A;
delete[] sl_1.b;
delete[] sl_2.b;
delete[] sl_3.b;
delete[] x1;
delete[] x2;
delete[] x3;
delete[] b1;
delete[] b2;
delete[] b3;
delete[] x_0_1;
delete[] x_0_2;
delete[] x_0_3;
delete[] solve_1;
delete[] solve_2;
delete[] solve_3;
}
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{4585c8f4-9e57-4635-9d35-533b259edfa5}</ProjectGuid>
<RootNamespace>NMSaidbatalovLR5</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<FloatingPointModel>Fast</FloatingPointModel>
<Optimization>MaxSpeed</Optimization>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<EnableEnhancedInstructionSet>
</EnableEnhancedInstructionSet>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="SLAE.cpp" />
<ClCompile Include="NM_Saidbatalov_LR5.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="SLAE.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="NM_Saidbatalov_LR5.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="SLAE.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SLAE.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
#include "SLAE.h"
double** genStripMatrix(int n, int l, double q)
{
double** A = new double* [n];
for (int i = 0; i < n; i++)
{
A[i] = new double[n];
for (int j = 0; j < n; j++)
{
A[i][j] = 0.;
}
}
auto x_dist = std::uniform_real_distribution<>(-1., 1.);
auto rng = std::default_random_engine();
for (int i = 0; i < n; i++)
{
int left;
int right;
if (0 > i - l)
left = 0;
else left = i - l;
if (i + l < n)
right = i + l + 1;
else
right = n;
for (int j = left; j < right; j++)
{
if (i == j) continue;
A[i][j] = x_dist(rng);
A[i][i] += fabs(A[i][j]);
A[i][i] *= q;
}
}
return A;
}
double* genVector(int n)
{
auto x_dist = std::uniform_real_distribution<>(-1., 1.);
auto rng = std::default_random_engine();
double* x = new double[n];
for (int i = 0; i < n; i++)
{
x[i] = x_dist(rng);
}
return x;
}
double* getB(double** A, double* x, int n)
{
double* b = new double[n];
for (int i = 0; i < n; i++)
{
b[i] = 0.;
for (int j = 0; j < n; j++)
{
b[i] += A[i][j] * x[j];
}
}
return b;
}
SLAE symmetrization(double** A, double* b, int n, int l)
{
SLAE slae;
double** _A = new double* [n];
double* _b = new double[n];
for (int i = 0; i < n; i++)
{
_A[i] = new double[n];
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
_A[i][j] = 0.;
for (int k = 0; k < n; k++)
{
_A[i][j] += A[k][i] * A[k][j];
}
//std::cout << _A[i][j] << "\t";
}
//std::cout << std::endl;
}
slae.A = new double* [n];
for (int i = 0; i < n; i++)
{
slae.A[i] = new double[2 * l + 1];
}
/////////////////////////////// ,
int L = 0;
for (int k = 2 * l; k >= 0; k--)
{
for (int i = 0; i < L; i++)
{
slae.A[i][k] = 0.0;
}
for (int i = L; i < n; i++)
{
slae.A[i][k] = _A[i - L][i];
}
L++;
}
for (int i = 0; i < n; i++)
{
_b[i] = 0.;
for (int j = 0; j < n; j++)
{
_b[i] += A[j][i] * b[j];
}
}
///////////////////////////////
slae.b = _b;
return slae;
}
double* Jacobi(SLAE sl, double* x, int n, int L, double eps)
{
double* x_k = new double[n + 1];
double* temp = new double[n];
int it = 0;
double norm;
for (int i = 0; i < n; i++)
{