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
fe785113
Commit
fe785113
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
ModSim: Finished ass4 code.
parent
cf6a9736
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modsim/ass2/Makefile
+1
-1
1 addition, 1 deletion
modsim/ass2/Makefile
modsim/ass2/q4.c
+40
-8
40 additions, 8 deletions
modsim/ass2/q4.c
with
41 additions
and
9 deletions
modsim/ass2/Makefile
+
1
−
1
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
...
...
This diff is collapsed.
Click to expand it.
modsim/ass2/q4.c
+
40
−
8
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
;
}
}
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