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

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

parent e9b93bfb

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_LR3_Kozlova", "NM_LR3_Kozlova\NM_LR3_Kozlova.vcxproj", "{613120E5-BF42-4746-8A7D-C93414CF8B84}"
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
{613120E5-BF42-4746-8A7D-C93414CF8B84}.Debug|x64.ActiveCfg = Debug|x64
{613120E5-BF42-4746-8A7D-C93414CF8B84}.Debug|x64.Build.0 = Debug|x64
{613120E5-BF42-4746-8A7D-C93414CF8B84}.Debug|x86.ActiveCfg = Debug|Win32
{613120E5-BF42-4746-8A7D-C93414CF8B84}.Debug|x86.Build.0 = Debug|Win32
{613120E5-BF42-4746-8A7D-C93414CF8B84}.Release|x64.ActiveCfg = Release|x64
{613120E5-BF42-4746-8A7D-C93414CF8B84}.Release|x64.Build.0 = Release|x64
{613120E5-BF42-4746-8A7D-C93414CF8B84}.Release|x86.ActiveCfg = Release|Win32
{613120E5-BF42-4746-8A7D-C93414CF8B84}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2AC3E22B-8196-415B-885A-7B049444D625}
EndGlobalSection
EndGlobal
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include <iostream>
#include <fstream>
#include "SoLAE.h"
#include <sstream>
#include <random>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
//для задачи 1 и 2
int n = 6; // количество узлов. Следоватекльно, p + q = 5. Т.к. p <= q, то p=2, q=3
int p = 2;
int q = 3;
double x[6] = { -0.5 , -0.100 , 0.30 , 0.70 , 1.10 , 1.50 };
double y[6] = { -2.8276, -0.24862, -0.72244, -1.9749, -1.1225, -0.59738 };
//n - уравнений, n + 1 неизвестная, зафиксируем, например a0 = 1;
//получим n - уравнений с n неизвестными.
double a_0 = 1.;
double** A = new double* [n];
for (int i = 0; i < n; i++)
{
A[i] = new double[n + 1];
}
for (int i = 0; i < n; i++)
{
for (int j = 1; j <= p; j++)
{
A[i][j - 1] = pow(x[i], j);
}
for (int j = 0; j <= q; j++)
{
A[i][j + p] = -y[i] * pow(x[i], j);
}
A[i][n] = -a_0;
}
cout << "Матрица для задачи 1 и 2:" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 1; j < n; j++)
{
cout << A[i][j] << " ";
}
cout << " | " << A[i][n] << endl;
}
double* coef = new double[7];
coef[0] = a_0; // a0 = 1
double* solve = new double[6];
//задание 1
cout << "Задание 1" << endl;
solve = Gauss(A, 6);
for (int i = 1; i < 7; i++)
{
coef[i] = solve[i - 1];
}
cout << "Коэффициенты рациональной итерполяции: Метод Гаусса" << endl;
for (int i = 0; i <= p; i++)
{
std::cout << "a" << i << " = " << coef[i] << std::endl;
}
for (int i = 0; i <= q; i++)
{
std::cout << "b" << i << " = " << coef[i + p + 1] << std::endl;
}
cout << "---------------------------------------------------" << endl;
// Задание 2
cout << "Задание 2" << endl;
solve = LU(A, 6);
cout << "Коэффициенты рациональной итерполяции: Метод LU разложения" << endl;
for (int i = 1; i < 7; i++)
{
coef[i] = solve[i - 1];
}
for (int i = 0; i <= p; i++)
{
std::cout << "a" << i << " = " << coef[i] << std::endl;
}
for (int i = 0; i <= q; i++)
{
std::cout << "b" << i << " = " << coef[i + p + 1] << std::endl;
}
cout << "---------------------------------------------------" << endl;
delete[] coef;
delete[] solve;
for (int i = 0; i < n; i++)
{
delete[] A[i];
}
delete[] A;
// Задание 3
cout << "Задание 3" << endl;
ofstream file;
double delta = 0.;
int n_opt;
for (int i = 1; i <= 12; i++)
{
stringstream str;
string F2;
str << i;
str >> F2;
string F1 = "ApproxPolinom";
string F3 = ".txt";
file.open(F1 + F2 + F3);
double* a = approx_Polinom(0., 2., 20, i, f);
int N = pow(10, 4);
double h = 2. / (N + 1);
for (int j = 0; j < N; j++)
{
double y = 0.;
for (int k = 0; k <= i; k++)
{
y += a[k] * pow(j * h, k);
}
file << j * h << "\t" << y;
if (j < 20)
{
file << "\t" << j * 0.10526316 << "\t" << f(j * 0.10526316);
}
file << endl;
}
file.close();
double sum = 0.;
for (int j = 0; j < 20; j++)
{
double y = 0.;
for (int k = 0; k <= i; k++)
{
y += a[k] * pow(j * 0.10526316, k);
}
sum += pow(fabs(y - f(j * 0.10526316)), 2);
}
if (delta == 0)
{
delta = sum;
n_opt = i;
}
else if (sum < delta)
{
delta = sum;
n_opt = i;
}
cout << "Степень апроксимириуещего многочлена: " << i << endl << "Сумма квадратов отклонений " << sum << endl;
}
cout << "Оптимальная степень: " << n_opt << " ,сумма квадратов отклонений в узлах сетки: " << delta << endl;
cout << "---------------------------------------------------" << endl;
// Задание 4
cout << "Задание 4" << endl;
auto x_dist = std::uniform_int_distribution<>(1, 8);
auto rng = std::default_random_engine();
int N = 5;
double** B = gen_matrix(N);
double* F = new double[N + 1];
for (int i = 0; i <= N; i++)
{
F[i] = B[i][N + 1];
}
double* root = sweep(B, N);
cout << "Решение методом прогонки:" << endl;
for (int i = 0; i <= N; i++)
{
std::cout << "x" << i + 1 << " = " << root[i] << std::endl;
}
for (int i = 0; i <= N; i++)
{
delete[] B[i];
}
delete[] root;
delete[] B;
delete[] F;
return 0;
}
<?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>{613120e5-bf42-4746-8a7d-c93414cf8b84}</ProjectGuid>
<RootNamespace>NMLR3Kozlova</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>
</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="NM_LR3_Kozlova.cpp" />
<ClCompile Include="SoLAE.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="SoLAE.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_LR3_Kozlova.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="SoLAE.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SoLAE.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
#include "SoLAE.h"
double f(double x)
{
return x * sin(x) * cos(2. * x);
}
double* Gauss(double** A, int n)
{
double t;
double* x = new double[n];
int i, j, k, j_max, count = 0;//j - , i - ;
//
for (k = 0; k < n; k++)
{
j_max = k;
for (j = k; j < n; j++)
if (fabs(A[j_max][k]) < fabs(A[j][k]))
j_max = j;
//
for (i = 0; i < n + 1; i++)
{
t = A[k][i];
A[k][i] = A[j_max][i];
A[j_max][i] = t;
}
//
if (A[j_max][k] == 0)
{
count = 0;
for (i = 0; i < n; i++)
{
if (A[k][i] == 0)
count++;
if (count == n && A[k][n] == 0)// . = 0 . = 0
{
throw std::exception("SLAE has many solutions");
}
else if (count == n && A[k][n] != 0)// . = 0 . 0
{
throw std::exception("SLAE has no solutions");
}
}
}
//
for (j = n; j >= k; j--)
A[k][j] = A[k][j] / A[k][k];// . a[1][1],a[2][2] ..
for (i = k + 1; i < n; i++)
for (j = n; j >= k; j--)
A[i][j] = A[i][j] - A[i][k] * A[k][j];// 2 - 1- . . .. */
}
//
for (i = 0; i < n; i++)
x[i] = A[i][n];
for (i = n - 2; i >= 0; i--)
for (j = i + 1; j < n; j++)
x[i] = x[i] - x[j] * A[i][j];//
////
//std::cout << "root of SLAE:" << std::endl;
//for (i = 0; i < n; i++)
// std::cout << "x" << i + 1 << " = " << x[i] << std::endl;
return x;
}
void inversion(double** A, int N)
{
double temp;
double** E = new double* [N];
for (int i = 0; i < N; i++)
E[i] = new double[N];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
{
E[i][j] = 0.0;
if (i == j)
E[i][j] = 1.0;
}
for (int k = 0; k < N; k++)
{
temp = A[k][k];
for (int j = 0; j < N; j++)
{
A[k][j] /= temp;
E[k][j] /= temp;
}
for (int i = k + 1; i < N; i++)
{
temp = A[i][k];
for (int j = 0; j < N; j++)
{
A[i][j] -= A[k][j] * temp;
E[i][j] -= E[k][j] * temp;
}
}
}
for (int k = N - 1; k > 0; k--)
{
for (int i = k - 1; i >= 0; i--)
{
temp = A[i][k];
for (int j = 0; j < N; j++)
{
A[i][j] -= A[k][j] * temp;
E[i][j] -= E[k][j] * temp;
}
}
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
A[i][j] = E[i][j];
for (int i = 0; i < N; i++)
delete[] E[i];
delete[] E;
}
double** matrix_multi(double** A, double** B, int n)
{
double** result = new double* [n];
//
for (int row = 0; row < n; row++) {
result[row] = new double[n];
for (int col = 0; col < n; col++) {
result[row][col] = 0;
}
}
for (int row = 0; row < n; row++) {
for (int col = 0; col < n; col++) {
for (int j = 0; j < n; j++) {
result[row][col] += A[row][j] * B[j][col];
}
}
}
return result;
}
double* LU(double** A, int n)
{