forked from mecchmatProjects/CppCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.17v.c
More file actions
26 lines (21 loc) · 717 Bytes
/
2.17v.c
File metadata and controls
26 lines (21 loc) · 717 Bytes
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
#include <stdio.h>
#include <stdlib.h>
float softSign(float x) {
float f = 1 + abs(x);
float res = 1/f;
return res;
}
int main(int argc, char *argv[]) {
float func = softSign(5);
printf("%f", func);
printf("\n");
float x = 1; // òî÷êà, â ÿê³é âè÷èñëÿºìî ïîõ³äíó
float h = 0.1; // êðîê ç ÿêèì âè÷èñëÿºìî ïîõ³äíó
// ïðèáëèçíî âè÷èñëÿºìî ïåðøó ïîõ³äíó ð³çíèìè ñïîñîáàìè
float fl = (softSign(x) - softSign(x - h)) / h; // ë³âà
float fr = (softSign(x + h) - softSign(x)) / h; // ïðàâà
float fc = (softSign(x + h) - softSign(x - h)) / (2 * h); // öåíòðàëüíà
float f2 = (softSign(x + h) - 2 * softSign(x) + softSign(x - h)) / (h * h);
printf("%f", f2);
return 0;
}