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
fe785113
Commit
fe785113
authored
Mar 02, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModSim: Finished ass4 code.
parent
cf6a9736
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
9 deletions
+41
-9
modsim/ass2/Makefile
modsim/ass2/Makefile
+1
-1
modsim/ass2/q4.c
modsim/ass2/q4.c
+40
-8
No files found.
modsim/ass2/Makefile
View file @
fe785113
...
@@ -9,7 +9,7 @@ q%: q%.o
...
@@ -9,7 +9,7 @@ q%: q%.o
q2
:
bisection.o
q2
:
bisection.o
q3
:
bisection.o regula_falsi.o newton_raphson.o
q3
:
bisection.o regula_falsi.o newton_raphson.o
q4
:
newton_raphson.o
q4
:
bisection.o regula_falsi.o
newton_raphson.o
q5
:
integral.o
q5
:
integral.o
q6
:
integral.o
q6
:
integral.o
...
...
modsim/ass2/q4.c
View file @
fe785113
...
@@ -2,9 +2,11 @@
...
@@ -2,9 +2,11 @@
#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include <math.h>
#include "newton_raphson.h"
#include "newton_raphson.h"
#include "bisection.h"
#include "regula_falsi.h"
#define EPSILON 1e-11
#define EPSILON 1e-11
#define
BISEC_STEPS 5
#define
MAX_STEPS 100000
/*
/*
* Manually define the functions and their derivatives.
* Manually define the functions and their derivatives.
...
@@ -34,14 +36,44 @@ double df3(double x) {
...
@@ -34,14 +36,44 @@ double df3(double x) {
return
(
x
*
x
+
1
)
+
2
*
x
*
(
x
-
4
);
return
(
x
*
x
+
1
)
+
2
*
x
*
(
x
-
4
);
}
}
int
main
(
void
)
{
#define PRINT_ZERO(f, df, x_start) { \
unsigned
int
steps
;
if( !isnan(root = newton_raphson(&f, &df, x_start, EPSILON, &steps, MAX_STEPS)) ) \
double
root
;
printf(#f ": %.11f (%d steps from start point %.11f)\n", root, steps, (double)x_start); \
else \
printf(#f ": could not find a root after %d steps\n", steps); \
}
#define PRINT_ZERO_RANGE(f, df, method, lnbd, ubnd) { \
x_start = method(&f, lnbd, ubnd, EPSILON, &start_steps, max_start_steps); \
printf("Did first %d steps using " #method "\n", start_steps); \
PRINT_ZERO(f, df, x_start); \
}
int
main
(
int
argc
,
char
*
argv
[])
{
unsigned
int
steps
,
start_steps
,
max_start_steps
;
double
root
,
x_start
;
if
(
argc
!=
2
)
{
printf
(
"Usage: %s START_STEPS
\n
"
,
argv
[
0
]);
return
1
;
}
max_start_steps
=
atoi
(
argv
[
1
]);
PRINT_ZERO
(
f1
,
df1
,
0
);
PRINT_ZERO
(
f2
,
df2
,
-
10
);
PRINT_ZERO
(
f2
,
df2
,
10
);
PRINT_ZERO
(
f3
,
df3
,
0
);
printf
(
"
\n
Now using Bisection to determine the first %d steps.
\n\n
"
,
max_start_steps
);
PRINT_ZERO_RANGE
(
f2
,
df2
,
bisec
,
0
,
10
);
PRINT_ZERO_RANGE
(
f3
,
df3
,
bisec
,
0
,
10
);
printf
(
"
\n
Now using Regula Falsi to determine the first %d steps.
\n\n
"
,
max_start_steps
);
if
(
!
isnan
(
root
=
newton_raphson
(
&
f2
,
&
df2
,
1000000
,
EPSILON
,
&
steps
,
100000
))
)
PRINT_ZERO_RANGE
(
f2
,
df2
,
regula_falsi
,
0
,
10
);
printf
(
"f2: %.11f (%d steps)
\n
"
,
root
,
steps
);
PRINT_ZERO_RANGE
(
f3
,
df3
,
regula_falsi
,
0
,
10
);
else
printf
(
"f2: could not find a root after %d steps
\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