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
02f831b4
Commit
02f831b4
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
ModSim ass3: Added log function.
parent
6d2f51b7
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/ass3/methods.c
+22
-7
22 additions, 7 deletions
modsim/ass3/methods.c
modsim/ass3/methods.h
+3
-0
3 additions, 0 deletions
modsim/ass3/methods.h
with
25 additions
and
7 deletions
modsim/ass3/methods.c
+
22
−
7
View file @
02f831b4
...
...
@@ -18,6 +18,11 @@ All functions return 0 upon success, or -1 when a computational error
occurs (overflow, NaN or such)
*/
#define LOG(t, y) { \
if( log_func != NULL ) \
log_func(t, y); \
}
int
Euler
(
double
t0
,
double
t1
,
double
dt
,
double
*
y0
,
double
*
y1
,
int
N
,
f_ptr
f
,
void
*
params
)
{
int
i
,
j
,
intervals
=
(
t1
-
t0
)
/
dt
;
...
...
@@ -27,6 +32,8 @@ int Euler(double t0, double t1, double dt, double *y0, double *y1, int N,
for
(
j
=
0
;
j
<
N
;
j
++
)
y1
[
j
]
=
y0
[
j
];
LOG
(
t0
,
y0
)
// Estimate for each interval
for
(
i
=
0
;
i
<
intervals
;
i
++
)
{
if
(
f
(
t
,
y1
,
dy
,
params
)
)
{
...
...
@@ -34,10 +41,11 @@ int Euler(double t0, double t1, double dt, double *y0, double *y1, int N,
return
-
1
;
}
for
(
j
=
0
;
j
<
N
;
j
++
)
{
for
(
j
=
0
;
j
<
N
;
j
++
)
y1
[
j
]
=
y1
[
j
]
+
dy
[
j
]
*
dt
;
// Value can be printed/logged here
}
// Value can be printed/logged here
LOG
(
t
,
y1
);
t
=
t0
+
i
*
dt
;
}
...
...
@@ -54,6 +62,8 @@ int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
for
(
j
=
0
;
j
<
N
;
j
++
)
y1
[
j
]
=
y0
[
j
];
LOG
(
t0
,
y0
)
// Estimate for each interval
for
(
i
=
0
;
i
<
intervals
;
i
++
)
{
if
(
f
(
t
,
y1
,
dy1
,
params
)
||
f
(
t
+
dt
,
y1
,
dy2
,
params
)
)
{
...
...
@@ -61,10 +71,11 @@ int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
return
-
1
;
}
for
(
j
=
0
;
j
<
N
;
j
++
)
{
for
(
j
=
0
;
j
<
N
;
j
++
)
y1
[
j
]
=
y1
[
j
]
+
.
5
*
(
dy1
[
j
]
+
dy2
[
j
])
*
dt
;
// Value can be printed/logged here
}
// Value can be printed/logged here
LOG
(
t
,
y1
);
t
=
t0
+
i
*
dt
;
}
...
...
@@ -81,6 +92,8 @@ 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
];
LOG
(
t0
,
y0
)
// Estimate for each interval
for
(
i
=
0
;
i
<
intervals
;
i
++
)
{
if
(
f
(
t
,
y1
,
dy
,
params
)
)
{
...
...
@@ -121,9 +134,11 @@ int RungeKutta4(double t0, double t1, double dt, double *y0, double *y1, int N,
for
(
j
=
0
;
j
<
N
;
j
++
)
{
e4
=
dy
[
j
]
*
dt
;
y1
[
j
]
=
y1
[
j
]
+
(
e1
[
j
]
+
2
*
(
e2
[
j
]
+
e3
[
j
])
+
e4
)
/
6
;
// Value can be printed/logged here
}
// Value can be printed/logged here
LOG
(
t
,
y1
);
t
=
t0
+
i
*
dt
;
}
...
...
This diff is collapsed.
Click to expand it.
modsim/ass3/methods.h
+
3
−
0
View file @
02f831b4
typedef
int
(
*
f_ptr
)(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
);
typedef
void
(
*
log_function
)(
double
t
,
double
*
y
);
log_function
log_func
=
NULL
;
int
Euler
(
double
t0
,
double
t1
,
double
dt
,
double
*
y0
,
double
*
y1
,
int
N
,
f_ptr
f
,
void
*
params
);
...
...
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