Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
5d35c0c1
Commit
5d35c0c1
authored
Mar 01, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished assignment 6.
parent
b1414ded
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
13 deletions
+30
-13
modsim/ass2/q6.c
modsim/ass2/q6.c
+30
-13
No files found.
modsim/ass2/q6.c
View file @
5d35c0c1
...
@@ -4,18 +4,26 @@
...
@@ -4,18 +4,26 @@
#include "func_ptr.h"
#include "func_ptr.h"
#include "integral.h"
#include "integral.h"
#define STRIDE 10000
double
accurate_integral
(
func_ptr
f
,
method_ptr
method
,
double
a
,
double
accurate_integral
(
func_ptr
f
,
method_ptr
method
,
double
a
,
double
b
,
double
accuracy
,
unsigned
int
stride
)
{
double
b
,
double
accuracy
,
unsigned
int
decimals
)
{
unsigned
int
steps
=
0
;
unsigned
int
steps
=
5000
,
i
,
prefix
;
double
result
,
old
;
double
result
=
0
,
old
=
1
;
do
{
while
(
fabs
(
old
-
result
)
>=
accuracy
)
{
steps
+=
stride
;
steps
*=
2
;
old
=
result
;
old
=
result
;
result
=
integral
(
f
,
method
,
a
,
b
,
steps
);
result
=
integral
(
f
,
method
,
a
,
b
,
steps
);
}
while
(
fabs
(
old
-
result
)
>=
accuracy
);
}
for
(
decimals
+=
2
,
prefix
=
(
int
)
result
;
prefix
;
prefix
/=
10
)
decimals
++
;
printf
(
"%.30f
\n
"
,
old
);
for
(
i
=
0
;
i
<
decimals
;
i
++
)
printf
(
" "
);
printf
(
"| could deviate from here
\n
%.30f
\n
"
,
result
);
return
result
;
return
result
;
}
}
...
@@ -24,12 +32,21 @@ double f1(double x) {
...
@@ -24,12 +32,21 @@ double f1(double x) {
return
x
*
pow
(
M_E
,
-
x
);
return
x
*
pow
(
M_E
,
-
x
);
}
}
#define PRINT_INTEGRAL(func, method, a, b, acc) (printf(#func " from " #a " to " \
#define PRINT_INTEGRAL(func, method, a, b, decimals) { \
#b " using %-19s %.11e", accurate_itegral(&func, &method, a, b, acc, STRIDE), \
double real = 0; \
#method " method:"))
double _i = accurate_integral(&func, &method, a, b, \
pow(10, -1.0 * decimals), decimals); \
printf(#func " from " #a " to " #b " using %-19s %.11e (%.8e%%)\n", \
#method " method:", _i, fabs(_i - real)); \
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
2
)
{
printf
(
"Usage: %s DECIMALS"
,
argv
[
0
]);
return
1
;
}
int
main
(
void
)
{
PRINT_INTEGRAL
(
f1
,
gauss
,
0
,
2
,
atoi
(
argv
[
1
]));
PRINT_INTEGRAL
(
f1
,
gauss
,
0
,
2
,
1e-5
);
return
0
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment