ГОСУДАРСТВЕННЫЙ КОМИТЕТ РОССИЙСКОЙ ФЕДЕРАЦИИ
ПО ВЫСШЕМУ И СРЕДНЕСПЕЦИАЛЬНОМУ ОБРАЗОВАНИЮ
КРАСНОЯРСКИЙ ГОСУДАРСТВЕННЫЙ ТЕХНИЧЕСКИЙ УНИВЕРСИТЕТ
Практическое задание
по компьютерной алгебре
тема: построение
кубического сплайна функции
Выполнил:
студент 2 курса ФИВТ
группы 27-4
Попов А.В.
Проверила:
Быкова Е.Г.
1998 г.
План:
вывод расчётных формул;
текст программы;
тестирование.
Текст программы.
#include
#include
#include
#include #include #include “mat_vec.h” // классы для работы с матрицами и векторами #include “progonka.h” // решение системы ур-ний (для 3-х диагональных #include “funct.h” // второстепеннные функции программы (рисование и // “корень” программы void spline (float step, int dop, int n, double* &x,double* &y,double* int k = 0; matrica Sp(n, n-1); for (int i = 1; i 1) Sp(i,i-1) = 1; } float *tmp; progonka(Sp, tmp); // решение системы уравнений методом прогонки // (см. файл “progonka.h”) vector a(n),b(n+1),c(n),d(n); // вычисление коэф-тов многочленов b(1) = 0; b(n+1) = 0; for(int index = 0; index > n; cout > dop; cout > step; dop++; double *x,*y, *x1,*y1; initial(x,y,x1,y1,n,dop); int i = 0; while (i // инициализация графики void init() { int D,M; D = DETECT; M = 5; initgraph(&D,&M,””); } // рисование графика функции и сплайна void paint(int Fx,int Fy,int key,int n, int dop, double* &x,double* int i = 0, a, b; a = getmaxx()/2; b = getmaxy()/2; setfillstyle(0,0); bar(0,0,a*2+1,b*2+1); setcolor(5); if ((key == 1) || (key == 3)) while ( i #include // класс матриц class matrica { public: const int Column, String; //кол-во столбцов и строк матрицы matrica(int column, int string); ~matrica(); private: float **WW; matrica(const matrica& rhs); matrica& operator=(const matrica& rhs); public: float& operator()(int i, int j); friend ostream& operator>(istream& in, const matrica& matr); }; // конструктор matrica :: matrica(int column, int string) : Column(column), WW = new float*[string]; if(!WW) { cout 0) && (i 0) && (j >(istream& in, matrica& WW) { for(int i = 1; i > WW(i, j); return in; } // класс векторов class vector { public: vector(int column); ~vector(); const int Column; // кол-во элементов вектора private: float *vect; vector(const vector& rhs); vector& operator=(const vector& rhs); public: float& operator()(int i); friend ostream& operator>(istream& in, const vector& vec); }; // кнструктор vector vector :: vector(int column) : Column(column) { vect = new float[column]; if(!vect) { cout 0) && (i >(istream& in, vector& vec) { for(int i = 1; i > vec(i); return in; } #endif #ifndef __PROGONKA_H #define __PROGONKA_H #include “mat_vec.h” int progonka(matrica &mat, float* &x) { x = new float[mat.String]; if(!x) return 0; int i, y = mat.Column, n = mat.String; vector h(n), d(n); d(1) = – mat(1, 2) / mat(1, 1); h(1) = mat(1, y) / mat(1, 1); for(i = 2; i = 1; i–) x[i – 1] = d(i) * x[i] + h(i); return 1; } #endif Тестирование: построенный в пределе от –5 до 5, с шагом = 1. Красным цветом – график сплайна, полученный при интерполировании
матриц)
т.д.)
&x1,double* &y1) {
&y,double* &x1,double* &y1) {
String(string) {
исходного графика, причём дополнительно построено всего 3 точки на
каждом интервале.
Нашли опечатку? Выделите и нажмите CTRL+Enter