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
0c91e4d7
Commit
0c91e4d7
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Finished ass3.
parent
2f7c9750
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/newton_raphson.h
+4
-5
4 additions, 5 deletions
modsim/ass2/newton_raphson.h
modsim/ass2/q3.c
+8
-4
8 additions, 4 deletions
modsim/ass2/q3.c
modsim/ass2/q4.c
+1
-1
1 addition, 1 deletion
modsim/ass2/q4.c
modsim/ass2/regula_falsi.h
+1
-1
1 addition, 1 deletion
modsim/ass2/regula_falsi.h
with
14 additions
and
11 deletions
modsim/ass2/newton_raphson.h
+
4
−
5
View file @
0c91e4d7
#include
"func_ptr.h"
#define MAX_STEPS 1000
double
newton_raphson
(
func_ptr
f
,
func_ptr
df
,
double
x_start
,
unsigned
int
*
steps
)
{
double
newton_raphson
(
func_ptr
f
,
func_ptr
df
,
double
x_start
,
double
epsilon
,
unsigned
int
*
steps
,
unsigned
int
max_steps
)
{
double
x
=
x_start
,
last_x
=
x
-
1
;
for
(
*
steps
=
0
;
x
!=
last_x
;
(
*
steps
)
++
)
{
if
(
*
steps
==
MAX_STEPS
)
for
(
*
steps
=
0
;
fabs
(
x
-
last_x
)
>=
epsilon
;
(
*
steps
)
++
)
{
if
(
*
steps
==
max_steps
)
return
NAN
;
last_x
=
x
;
...
...
This diff is collapsed.
Click to expand it.
modsim/ass2/q3.c
+
8
−
4
View file @
0c91e4d7
...
...
@@ -3,6 +3,7 @@
#include
<math.h>
#include
"bisec.h"
#include
"newton_raphson.h"
#include
"regula_falsi.h"
#define EPSILON 1e-11
...
...
@@ -17,11 +18,14 @@ double df(double x) {
int
main
(
void
)
{
unsigned
int
steps
;
printf
(
"Square root of 2 using bisection method:
%.11
f (%d steps)
\n
"
,
bisec
(
&
f
,
1
.
4
,
1
.
5
,
EPSILON
,
&
steps
),
steps
);
printf
(
"Square root of 2 using bisection method:
%.20
f (%d steps)
\n
"
,
bisec
(
&
f
,
1
,
2
,
EPSILON
,
&
steps
),
steps
);
printf
(
"Square root of 2 using newton_raphson method: %.11f (%d steps)
\n
"
,
newton_raphson
(
&
f
,
&
df
,
1
.
4
,
&
steps
),
steps
);
printf
(
"Square root of 2 using Newton-Raphson method: %.20f (%d steps)
\n
"
,
newton_raphson
(
&
f
,
&
df
,
1
.
4
,
EPSILON
,
&
steps
,
100000
),
steps
);
printf
(
"Square root of 2 using the Regula Falsi method: %.20f (%d steps)
\n
"
,
regula_falsi
(
&
f
,
1
,
2
,
EPSILON
,
&
steps
,
100000
),
steps
);
return
0
;
}
This diff is collapsed.
Click to expand it.
modsim/ass2/q4.c
+
1
−
1
View file @
0c91e4d7
...
...
@@ -38,7 +38,7 @@ int main(void) {
unsigned
int
steps
;
double
root
;
if
(
!
isnan
(
root
=
newton_raphson
(
&
f2
,
&
df2
,
1000000
,
&
steps
))
)
if
(
!
isnan
(
root
=
newton_raphson
(
&
f2
,
&
df2
,
1000000
,
EPSILON
,
&
steps
,
100000
))
)
printf
(
"f2: %.11f (%d steps)
\n
"
,
root
,
steps
);
else
printf
(
"f2: could not find a root after %d steps
\n
"
,
steps
);
...
...
This diff is collapsed.
Click to expand it.
modsim/ass2/regula_falsi.h
+
1
−
1
View file @
0c91e4d7
...
...
@@ -2,7 +2,7 @@
#include
"func_ptr.h"
double
regula_falsi
(
func_ptr
f
,
double
s
,
double
t
,
double
e
,
int
*
steps
,
int
m
)
{
int
*
steps
,
unsigned
int
m
)
{
int
n
,
side
=
0
;
double
r
,
fr
,
fs
=
f
(
s
),
ft
=
f
(
t
);
...
...
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