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
ed8fe53c
Commit
ed8fe53c
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added assignment 3.
parent
d3de400b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
modsim/ass2/Makefile
+3
-0
3 additions, 0 deletions
modsim/ass2/Makefile
modsim/ass2/bisec.h
+23
-0
23 additions, 0 deletions
modsim/ass2/bisec.h
modsim/ass2/q2.c
+1
-24
1 addition, 24 deletions
modsim/ass2/q2.c
modsim/ass2/q3.c
+4
-27
4 additions, 27 deletions
modsim/ass2/q3.c
with
31 additions
and
51 deletions
modsim/ass2/Makefile
+
3
−
0
View file @
ed8fe53c
...
...
@@ -10,6 +10,9 @@ q1: q1.o
q2
:
q2.o
$(
CC
)
$(
CFLAGS
)
$(
LFLAGS
)
-o
$@
$^
q3
:
q3.o
$(
CC
)
$(
CFLAGS
)
$(
LFLAGS
)
-o
$@
$^
%.o
:
%.c
$(
CC
)
$(
CFLAGS
)
$(
LFLAGS
)
-o
$@
-c
$^
...
...
This diff is collapsed.
Click to expand it.
modsim/ass2/bisec.h
0 → 100644
+
23
−
0
View file @
ed8fe53c
#define EPSILON 1e-11
typedef
double
(
*
func_ptr
)(
double
x
);
double
bisec
(
func_ptr
f
,
double
left
,
double
right
,
int
*
steps
)
{
int
i
;
double
mid
;
for
(
i
=
1
;
fabs
(
right
-
left
)
>
2
*
EPSILON
;
i
++
)
{
mid
=
(
right
+
left
)
/
2
;
if
(
f
(
left
)
*
f
(
mid
)
<
0
)
right
=
mid
;
else
if
(
f
(
right
)
*
f
(
mid
)
<
0
)
left
=
mid
;
else
break
;
}
*
steps
=
i
;
return
mid
;
}
This diff is collapsed.
Click to expand it.
modsim/ass2/q2.c
+
1
−
24
View file @
ed8fe53c
#include
<stdlib.h>
#include
<stdio.h>
#include
<math.h>
#define EPSILON 1e-11
typedef
double
(
*
func_ptr
)(
double
x
);
double
bisec
(
func_ptr
f
,
double
left
,
double
right
,
int
*
steps
)
{
int
i
;
double
mid
;
for
(
i
=
1
;
fabs
(
right
-
left
)
>
2
*
EPSILON
;
i
++
)
{
mid
=
(
right
+
left
)
/
2
;
if
(
f
(
left
)
*
f
(
mid
)
<
0
)
right
=
mid
;
else
if
(
f
(
right
)
*
f
(
mid
)
<
0
)
left
=
mid
;
else
break
;
}
*
steps
=
i
;
return
mid
;
}
#include
"bisec.h"
double
func
(
double
x
)
{
return
x
*
sin
(
x
)
-
1
;
...
...
This diff is collapsed.
Click to expand it.
modsim/ass2/q3.c
+
4
−
27
View file @
ed8fe53c
#include
<stdlib.h>
#include
<stdio.h>
#include
<math.h>
#include
"bisec.h"
#define EPSILON 1e-11
typedef
double
(
*
func_ptr
)(
double
x
);
double
bisec
(
func_ptr
f
,
double
left
,
double
right
,
int
*
steps
)
{
int
i
;
double
mid
;
for
(
i
=
1
;
fabs
(
right
-
left
)
>
2
*
EPSILON
;
i
++
)
{
mid
=
(
right
+
left
)
/
2
;
if
(
f
(
left
)
*
f
(
mid
)
<
0
)
right
=
mid
;
else
if
(
f
(
right
)
*
f
(
mid
)
<
0
)
left
=
mid
;
else
break
;
}
*
steps
=
i
;
return
mid
;
}
double
func
(
double
x
)
{
return
x
*
sin
(
x
)
-
1
;
double
quad
(
double
x
)
{
return
x
*
x
-
2
;
}
int
main
(
void
)
{
int
steps
;
printf
(
"
zero point
: %.
20
f
\n
"
,
bisec
(
&
func
,
0
,
2
,
&
steps
));
printf
(
"
Square root of 2
: %.
11
f
\n
"
,
bisec
(
&
quad
,
1
.
4
,
1
.
5
,
&
steps
));
printf
(
"Steps: %d
\n
"
,
steps
);
return
0
;
...
...
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