Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
uva
Commits
cf6a9736
Commit
cf6a9736
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
ModSim: Added max_steps parameter to bisection method.
parent
dfcc5bcb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
modsim/ass2/bisection.c
+7
-4
7 additions, 4 deletions
modsim/ass2/bisection.c
modsim/ass2/bisection.h
+1
-1
1 addition, 1 deletion
modsim/ass2/bisection.h
modsim/ass2/q2.c
+1
-1
1 addition, 1 deletion
modsim/ass2/q2.c
modsim/ass2/q3.c
+1
-1
1 addition, 1 deletion
modsim/ass2/q3.c
with
10 additions
and
7 deletions
modsim/ass2/bisection.c
+
7
−
4
View file @
cf6a9736
#include
"bisection.h"
double
bisec
(
func_ptr
f
,
double
left
,
double
right
,
double
epsilon
,
unsigned
int
*
steps
)
{
double
mid
,
fmid
;
double
epsilon
,
unsigned
int
*
steps
,
unsigned
int
max_steps
)
{
double
mid
=
left
,
fmid
;
for
(
*
steps
=
0
;
fabs
(
right
-
left
)
>
2
*
epsilon
;
(
*
steps
)
++
)
{
for
(
*
steps
=
0
;
(
fabs
(
right
-
left
)
>
2
*
epsilon
)
&&
(
!
max_steps
||
(
*
steps
<
max_steps
));
(
*
steps
)
++
)
{
mid
=
(
right
+
left
)
/
2
;
if
(
f
(
left
)
*
(
fmid
=
f
(
mid
))
<
0
)
right
=
mid
;
else
if
(
f
(
right
)
*
fmid
<
0
)
left
=
mid
;
else
else
{
(
*
steps
)
++
;
break
;
}
}
return
mid
;
...
...
This diff is collapsed.
Click to expand it.
modsim/ass2/bisection.h
+
1
−
1
View file @
cf6a9736
...
...
@@ -5,6 +5,6 @@
#include
"func_ptr.h"
double
bisec
(
func_ptr
f
,
double
left
,
double
right
,
double
epsilon
,
unsigned
int
*
steps
);
double
epsilon
,
unsigned
int
*
steps
,
unsigned
int
max_steps
);
#endif
This diff is collapsed.
Click to expand it.
modsim/ass2/q2.c
+
1
−
1
View file @
cf6a9736
...
...
@@ -20,7 +20,7 @@ int main(int argc, char *argv[]) {
end
=
atoi
(
argv
[
2
]);
for
(
i
=
begin
;
i
<=
end
;
i
++
)
{
bisection
=
bisec
(
&
func
,
0
,
2
,
pow
(
10
,
-
1
.
0
*
i
),
&
steps
);
bisection
=
bisec
(
&
func
,
0
,
2
,
pow
(
10
,
-
1
.
0
*
i
),
&
steps
,
100000
);
printf
(
"zero point: %.30f for epsilon = 1e-%d (%d steps)
\n
"
,
bisection
,
i
,
steps
);
}
...
...
This diff is collapsed.
Click to expand it.
modsim/ass2/q3.c
+
1
−
1
View file @
cf6a9736
...
...
@@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {
for
(
i
=
begin
;
i
<=
end
;
i
++
)
{
epsilon
=
pow
(
10
,
-
1
.
0
*
i
);
tmp
=
bisec
(
&
f
,
1
,
2
,
epsilon
,
&
steps
);
tmp
=
bisec
(
&
f
,
1
,
2
,
epsilon
,
&
steps
,
100000
);
printf
(
"Sqrt(2) using bisection: %.20f (%d steps; epsilon=%.0e)
\n
"
,
tmp
,
steps
,
epsilon
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment