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
4d4df408
Commit
4d4df408
authored
14 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Patches
Plain Diff
Harm osc will write log to stdout.
parent
0db05df5
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/ass3/harm_osc.c
+9
-12
9 additions, 12 deletions
modsim/ass3/harm_osc.c
modsim/ass3/logger.c
+17
-5
17 additions, 5 deletions
modsim/ass3/logger.c
modsim/ass3/logger.h
+1
-1
1 addition, 1 deletion
modsim/ass3/logger.h
modsim/ass3/methods.c
+6
-6
6 additions, 6 deletions
modsim/ass3/methods.c
with
33 additions
and
24 deletions
modsim/ass3/harm_osc.c
+
9
−
12
View file @
4d4df408
...
...
@@ -7,23 +7,18 @@
#define DT .001
#define INTEGRATE(method, t0, t1, FN) { \
if( method(t0, t1, DT, y0, y1, 2, &f_ ## FN, args_ ## FN) ) \
puts("FAIL"); \
else \
printf("y1 using %-12s s:%.10f\n", #method ":", *y1); \
method(t0, t1, DT, y0, y1, 2, &f_ ## FN, args_ ## FN); \
/*if( method(t0, t1, DT, y0, y1, 2, &f_ ## FN, args_ ## FN) ) puts("FAIL");*/
\
/* else printf("y1 using %-12s s:%.10f\n", #method ":", *y1); */
\
}
#define COMPARE(t0, t1, fn) { \
printf("Function %s\n", #fn); \
/*
printf("Function %s\n", #fn);
*/
\
INTEGRATE(Euler, t0, t1, fn); \
INTEGRATE(RungeKutta2, t0, t1, fn); \
INTEGRATE(RungeKutta4, t0, t1, fn); \
}
//void log(double t, double *y) {
// printf("%f,%f,%f\n", t, y[0], y[1]);
//}
//
#define PARAM(n) ((double *) params)[n]
int
f_osc
(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
)
{
...
...
@@ -73,12 +68,14 @@ int main(void) {
COMPARE
(.
0
,
10
.
0
,
forced_osc
);
// TODO: this model is not yet completed.
printf
(
"Function: lottka_volt
\n
"
);
//
printf("Function: lottka_volt\n");
INTEGRATE
(
RungeKutta4
,
.
0
,
10
.
0
,
lottka_volt
);
// TODO: this model is not yet completed.
printf
(
"Function: modified_pp
\n
"
);
//
printf("Function: modified_pp\n");
INTEGRATE
(
RungeKutta4
,
.
0
,
10
.
0
,
modified_pp
);
logger_close
();
return
0
;
}
This diff is collapsed.
Click to expand it.
modsim/ass3/logger.c
+
17
−
5
View file @
4d4df408
...
...
@@ -2,12 +2,24 @@
FILE
*
logfile
=
NULL
;
void
logger
(
double
t
,
double
*
y
)
{
if
(
!
logfile
)
{
logfile
=
fopen
(
"methods.log"
,
"w"
);
}
void
logger_open
(
const
char
*
filename
)
{
if
(
logfile
)
logger_close
();
logfile
=
fopen
(
filename
,
"w"
);
}
fprintf
(
logfile
,
"%e,%e
\n
"
,
t
,
y
[
0
]);
void
logger
(
double
t
,
int
N
,
double
*
y
)
{
if
(
!
logfile
)
logfile
=
stdout
;
fprintf
(
logfile
,
"%e"
,
t
);
if
(
N
>
0
)
{
for
(
int
i
=
0
;
i
<
N
-
1
;
i
++
)
fprintf
(
logfile
,
",%e"
,
y
[
0
]);
fprintf
(
logfile
,
"%e
\n
"
,
y
[
N
-
1
]);
}
else
fprintf
(
logfile
,
"
\n
"
);
}
void
logger_close
()
{
...
...
This diff is collapsed.
Click to expand it.
modsim/ass3/logger.h
+
1
−
1
View file @
4d4df408
...
...
@@ -6,7 +6,7 @@
//typedef void (*log_function)(double t, double *y);
void
logger
(
double
t
,
double
*
y
);
void
logger
(
double
t
,
int
N
,
double
*
y
);
void
logger_close
();
#endif // __LOG_H__
This diff is collapsed.
Click to expand it.
modsim/ass3/methods.c
+
6
−
6
View file @
4d4df408
...
...
@@ -28,7 +28,7 @@ int Euler(double t0, double t1, double dt, double *y0, double *y1, int N,
for
(
j
=
0
;
j
<
N
;
j
++
)
y1
[
j
]
=
y0
[
j
];
logger
(
t0
,
y0
);
logger
(
t0
,
N
,
y0
);
// Estimate for each interval
for
(
i
=
0
;
i
<
intervals
;
i
++
)
{
...
...
@@ -41,7 +41,7 @@ int Euler(double t0, double t1, double dt, double *y0, double *y1, int N,
y1
[
j
]
=
y1
[
j
]
+
dy
[
j
]
*
dt
;
// Value can be printed/logged here
logger
(
t
,
y1
);
logger
(
t
,
N
,
y1
);
t
=
t0
+
i
*
dt
;
}
...
...
@@ -58,7 +58,7 @@ int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
for
(
j
=
0
;
j
<
N
;
j
++
)
y1
[
j
]
=
y0
[
j
];
logger
(
t0
,
y0
);
logger
(
t0
,
N
,
y0
);
// Estimate for each interval
for
(
i
=
0
;
i
<
intervals
;
i
++
)
{
...
...
@@ -71,7 +71,7 @@ int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
y1
[
j
]
=
y1
[
j
]
+
.
5
*
(
dy1
[
j
]
+
dy2
[
j
])
*
dt
;
// Value can be printed/logged here
logger
(
t
,
y1
);
logger
(
t
,
N
,
y1
);
t
=
t0
+
i
*
dt
;
}
...
...
@@ -88,7 +88,7 @@ int RungeKutta4(double t0, double t1, double dt, double *y0, double *y1, int N,
for
(
j
=
0
;
j
<
N
;
j
++
)
y
[
j
]
=
y1
[
j
]
=
y0
[
j
];
logger
(
t0
,
y0
);
logger
(
t0
,
N
,
y0
);
// Estimate for each interval
for
(
i
=
0
;
i
<
intervals
;
i
++
)
{
...
...
@@ -133,7 +133,7 @@ int RungeKutta4(double t0, double t1, double dt, double *y0, double *y1, int N,
}
// Value can be printed/logged here
logger
(
t
,
y1
);
logger
(
t
,
N
,
y1
);
t
=
t0
+
i
*
dt
;
}
...
...
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