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
4d4df408
Commit
4d4df408
authored
Apr 09, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Harm osc will write log to stdout.
parent
0db05df5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
24 deletions
+33
-24
modsim/ass3/harm_osc.c
modsim/ass3/harm_osc.c
+9
-12
modsim/ass3/logger.c
modsim/ass3/logger.c
+17
-5
modsim/ass3/logger.h
modsim/ass3/logger.h
+1
-1
modsim/ass3/methods.c
modsim/ass3/methods.c
+6
-6
No files found.
modsim/ass3/harm_osc.c
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
;
}
modsim/ass3/logger.c
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
()
{
...
...
modsim/ass3/logger.h
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__
modsim/ass3/methods.c
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
;
}
...
...
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