-
Notifications
You must be signed in to change notification settings - Fork 9
/
Tutorial-Differentiation.cpp
57 lines (40 loc) · 1.43 KB
/
Tutorial-Differentiation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*-------------------------------------------------------------------------------\
@ Numerical Methods by Young-Keun Kim - Handong Global University
Author : Jan Park
Created : 10-05-2021
Modified : 10-05-2021
Language/ver : C++ in MSVS2019
Description : [Tutorial]Differentiation.cpp
-------------------------------------------------------------------------------*/
#include "myNM.h"
// Define a function that defines the target equation.
double myFunc(const double x);
int main(int argc, char* argv[])
{
// PART 1
printf("\n**************************************************");
printf("\n| PART 1. |");
printf("\n**************************************************\n");
Matrix t = txt2Mat("", "Q1_vect");
Matrix x = txt2Mat("", "Q1_vecx");
Matrix vel = gradient(t, x);
Matrix acc = gradient(t, vel);
printMat(t, "t");
printMat(x, "x");
printMat(vel, "vel");
printMat(acc, "acc");
// PART 2
printf("\n**************************************************");
printf("\n| PART 2. |");
printf("\n**************************************************\n");
Matrix xin = txt2Mat("", "Q2_vecxin");
Matrix dydx = gradientFunc(myFunc, xin);
printMat(xin, "xin");
printMat(dydx, "dydx");
system("pause");
return 0;
}
// Define a function that defines the target equation.
double myFunc(const double x) {
return x * x * x;
}