Last change
on this file since 1117 was
1117,
checked in by sam, 11 years ago
|
math: move the Remez algorithm implementation to the core.
|
-
Property svn:keywords set to
Id
|
File size:
1.0 KB
|
Line | |
---|
1 | // |
---|
2 | // Lol Engine - Sample math program: Chebyshev polynomials |
---|
3 | // |
---|
4 | // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
9 | // |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include <cstdio> |
---|
16 | #include <cstdlib> |
---|
17 | |
---|
18 | #if USE_SDL && defined __APPLE__ |
---|
19 | # include <SDL_main.h> |
---|
20 | #endif |
---|
21 | |
---|
22 | #include "lol/math/real.h" |
---|
23 | #include "lol/math/matrix.h" |
---|
24 | #include "lol/math/remez.h" |
---|
25 | |
---|
26 | using lol::real; |
---|
27 | using lol::RemezSolver; |
---|
28 | |
---|
29 | /* The function we want to approximate */ |
---|
30 | real myfun(real const &y) |
---|
31 | { |
---|
32 | real x = sqrt(y); |
---|
33 | return (sin(x) - x) / (x * y); |
---|
34 | } |
---|
35 | |
---|
36 | real myerr(real const &y) |
---|
37 | { |
---|
38 | real x = sqrt(y); |
---|
39 | return sin(x) / (x * y); |
---|
40 | } |
---|
41 | |
---|
42 | int main(int argc, char **argv) |
---|
43 | { |
---|
44 | RemezSolver<2, real> solver; |
---|
45 | solver.Run(real::R_1 >> 400, real::R_PI_2 * real::R_PI_2, myfun, myerr, 40); |
---|
46 | |
---|
47 | return EXIT_SUCCESS; |
---|
48 | } |
---|
49 | |
---|
Note: See
TracBrowser
for help on using the repository browser.