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
ed8fe53c
Commit
ed8fe53c
authored
Feb 18, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added assignment 3.
parent
d3de400b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
51 deletions
+31
-51
modsim/ass2/Makefile
modsim/ass2/Makefile
+3
-0
modsim/ass2/bisec.h
modsim/ass2/bisec.h
+23
-0
modsim/ass2/q2.c
modsim/ass2/q2.c
+1
-24
modsim/ass2/q3.c
modsim/ass2/q3.c
+4
-27
No files found.
modsim/ass2/Makefile
View file @
ed8fe53c
...
@@ -10,6 +10,9 @@ q1: q1.o
...
@@ -10,6 +10,9 @@ q1: q1.o
q2
:
q2.o
q2
:
q2.o
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
q3
:
q3.o
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
%.o
:
%.c
%.o
:
%.c
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
-c
$^
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
-c
$^
...
...
modsim/ass2/bisec.h
0 → 100644
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
;
}
modsim/ass2/q2.c
View file @
ed8fe53c
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <math.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
)
{
double
func
(
double
x
)
{
return
x
*
sin
(
x
)
-
1
;
return
x
*
sin
(
x
)
-
1
;
...
...
modsim/ass2/q3.c
View file @
ed8fe53c
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include <math.h>
#include "bisec.h"
#define EPSILON 1e-11
double
quad
(
double
x
)
{
return
x
*
x
-
2
;
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
;
}
}
int
main
(
void
)
{
int
main
(
void
)
{
int
steps
;
int
steps
;
printf
(
"
zero point: %.20f
\n
"
,
bisec
(
&
func
,
0
,
2
,
&
steps
));
printf
(
"
Square root of 2: %.11f
\n
"
,
bisec
(
&
quad
,
1
.
4
,
1
.
5
,
&
steps
));
printf
(
"Steps: %d
\n
"
,
steps
);
printf
(
"Steps: %d
\n
"
,
steps
);
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