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
9fa04dd8
Commit
9fa04dd8
authored
Feb 28, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Movedd Newton-Raphson method to header file.
parent
d431e629
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
33 deletions
+21
-33
modsim/ass2/func_ptr.h
modsim/ass2/func_ptr.h
+5
-0
modsim/ass2/newton_raphson.h
modsim/ass2/newton_raphson.h
+15
-0
modsim/ass2/q4.c
modsim/ass2/q4.c
+1
-33
No files found.
modsim/ass2/func_ptr.h
View file @
9fa04dd8
#ifndef FUNC_PTR_H
#define FUNC_PTR_H
typedef
double
(
*
func_ptr
)(
double
);
typedef
double
(
*
func_ptr
)(
double
);
#endif
modsim/ass2/newton_raphson.h
0 → 100644
View file @
9fa04dd8
#include "func_ptr.h"
double
newton_raphson
(
func_ptr
f
,
func_ptr
df
,
double
x_start
,
int
*
steps
)
{
double
x
=
x_start
,
last_x
=
x
-
1
;
for
(
*
steps
=
0
;
x
!=
last_x
;
(
*
steps
)
++
)
{
if
(
*
steps
==
MAX_STEPS
)
return
NAN
;
last_x
=
x
;
x
-=
f
(
x
)
/
df
(
x
);
}
return
x
;
}
modsim/ass2/q4.c
View file @
9fa04dd8
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include <math.h>
#include "
func_ptr
.h"
#include "
newton_raphson
.h"
#define EPSILON 1e-11
#define EPSILON 1e-11
#define MAX_STEPS 1000
#define MAX_STEPS 1000
#define BISEC_STEPS 5
#define BISEC_STEPS 5
double
bisec_limited
(
func_ptr
f
,
double
left
,
double
right
,
int
max_steps
)
{
int
i
;
double
mid
;
for
(
i
=
0
;
fabs
(
right
-
left
)
>
2
*
EPSILON
&&
i
<
max_steps
;
i
++
)
{
mid
=
(
right
+
left
)
/
2
;
if
(
f
(
left
)
*
f
(
mid
)
<
0
)
right
=
mid
;
else
if
(
f
(
right
)
*
f
(
mid
)
<
0
)
left
=
mid
;
else
break
;
}
return
mid
;
}
double
newton_raphson
(
func_ptr
f
,
func_ptr
df
,
double
x_start
,
int
*
steps
)
{
double
x
=
x_start
,
last_x
=
x
-
1
;
for
(
*
steps
=
0
;
x
!=
last_x
;
(
*
steps
)
++
)
{
if
(
*
steps
==
MAX_STEPS
)
return
NAN
;
last_x
=
x
;
x
-=
f
(
x
)
/
df
(
x
);
}
return
x
;
}
/*
/*
* Manually define the functions and their derivatives.
* Manually define the functions and their derivatives.
*/
*/
...
...
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