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
22ff97f8
Commit
22ff97f8
authored
Feb 18, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Worked on ass4.
parent
836e82fe
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
4 deletions
+31
-4
modsim/ass2/q4.c
modsim/ass2/q4.c
+31
-4
No files found.
modsim/ass2/q4.c
View file @
22ff97f8
...
@@ -3,10 +3,35 @@
...
@@ -3,10 +3,35 @@
#include <math.h>
#include <math.h>
#include "func_ptr.h"
#include "func_ptr.h"
double
newton
(
func_ptr
f
,
func_ptr
df
,
double
x_start
)
{
#define EPSILON 1e-11
double
bisec_limited
(
func_ptr
f
,
double
left
,
double
right
,
int
max_steps
)
{
int
i
;
double
mid
;
return
0
;
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
(
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
)
++
)
{
last_x
=
x
;
x
-=
f
(
x
)
/
df
(
x
);
}
return
x
;
}
}
double
f1
(
double
x
)
{
double
f1
(
double
x
)
{
...
@@ -34,7 +59,9 @@ double df3(double x) {
...
@@ -34,7 +59,9 @@ double df3(double x) {
}
}
int
main
(
void
)
{
int
main
(
void
)
{
printf
(
"f1: %.11f
\n
"
,
newton
(
&
f1
,
&
df1
,
1
));
int
steps
;
printf
(
"f1: %.11f (%d steps)
\n
"
,
newton
(
&
f2
,
&
df2
,
-
100
,
&
steps
),
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