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
cf6a9736
Commit
cf6a9736
authored
Mar 02, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModSim: Added max_steps parameter to bisection method.
parent
dfcc5bcb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
7 deletions
+10
-7
modsim/ass2/bisection.c
modsim/ass2/bisection.c
+7
-4
modsim/ass2/bisection.h
modsim/ass2/bisection.h
+1
-1
modsim/ass2/q2.c
modsim/ass2/q2.c
+1
-1
modsim/ass2/q3.c
modsim/ass2/q3.c
+1
-1
No files found.
modsim/ass2/bisection.c
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
;
...
...
modsim/ass2/bisection.h
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
modsim/ass2/q2.c
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
);
}
...
...
modsim/ass2/q3.c
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
);
...
...
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