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
ad1a2ada
Commit
ad1a2ada
authored
Apr 08, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modsim ass3: Started work on question 1 (harmonic oscillator).
parent
a23b3172
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
modsim/ass3/Makefile
modsim/ass3/Makefile
+5
-2
modsim/ass3/harm_osc.c
modsim/ass3/harm_osc.c
+37
-0
No files found.
modsim/ass3/Makefile
View file @
ad1a2ada
...
...
@@ -2,10 +2,13 @@ CC=gcc
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-D_GNU_SOURCE
-g
-O0
LFLAGS
=
-lm
all
:
test
all
:
test
harm_osc
test
:
test.o methods.o
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
harm_osc
:
harm_osc.o methods.o
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
clean
:
rm
*
.o
test
rm
*
.o
test
harm_osc
modsim/ass3/harm_osc.c
0 → 100644
View file @
ad1a2ada
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "methods.h"
#define DT .001
#define INTEGRATE(method, t0, t1) { \
if( method(t0, t1, DT, y0, y1, 2, &f_osc, &k) ) \
puts("FAIL"); \
else \
printf("y1 using %-12s s:%.10f\n", #method ":", *y1); \
}
#define COMPARE(t0, t1) { \
INTEGRATE(Euler, t0, t1); \
INTEGRATE(RungeKutta2, t0, t1); \
INTEGRATE(RungeKutta4, t0, t1); \
}
/*
void log(double t, double *y) {
printf("%f,%f,%f\n", t, y[0], y[1]);
}
*/
int
f_osc
(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
)
{
dy
[
0
]
=
y
[
1
];
dy
[
1
]
=
-*
(
double
*
)(
params
)
*
y
[
0
];
return
0
;
}
int
main
(
void
)
{
double
k
=
.
5
,
y0
[
2
]
=
{.
0
,
5
.
0
},
y1
[
2
]
=
{.
0
,
.
0
};
COMPARE
(.
0
,
10
.
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