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
2ea1c77f
Commit
2ea1c77f
authored
May 19, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModSim ass4 taddeus: Worked on sequential program.
parent
36d87e81
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
19 deletions
+21
-19
modsim/ass4_taddeus/vibstring/plot.py
modsim/ass4_taddeus/vibstring/plot.py
+8
-8
modsim/ass4_taddeus/vibstring/seq.c
modsim/ass4_taddeus/vibstring/seq.c
+13
-11
No files found.
modsim/ass4_taddeus/vibstring/plot.py
View file @
2ea1c77f
...
@@ -4,19 +4,19 @@ from pylab import figure, plot, subplot, show, savefig, legend
...
@@ -4,19 +4,19 @@ from pylab import figure, plot, subplot, show, savefig, legend
from
time
import
sleep
from
time
import
sleep
# Collect data
# Collect data
data
=
{}
t
=
[]
y
=
[]
for
line
in
stdin
.
readlines
():
for
line
in
stdin
.
readlines
():
s
=
line
.
split
(
' '
)
s
=
line
.
split
(
' '
)
data
[
float
(
s
[
0
])]
=
[
map
(
float
,
s
[
1
::
2
]),
map
(
float
,
s
[
2
::
2
])]
t
.
append
(
float
(
s
[
0
]))
y
.
append
((
map
(
float
,
s
[
1
::
2
]),
map
(
float
,
s
[
2
::
2
])))
# Plot and optionally save data
# Plot and optionally save data
figure
(
len
(
data
))
figure
(
len
(
t
))
i
=
1
for
i
in
range
(
len
(
t
)):
for
t
in
data
:
subplot
(
2
,
5
,
i
+
1
)
subplot
(
2
,
5
,
i
)
plot
(
y
[
i
][
0
],
y
[
i
][
1
],
'x-'
,
label
=
't = %.3f'
%
t
[
i
])
plot
(
data
[
t
][
0
],
data
[
t
][
1
],
'x-'
,
label
=
't = %.3f'
%
t
)
#legend()
#legend()
i
+=
1
if
len
(
argv
)
==
2
:
if
len
(
argv
)
==
2
:
savefig
(
argv
[
1
])
savefig
(
argv
[
1
])
show
()
show
()
modsim/ass4_taddeus/vibstring/seq.c
View file @
2ea1c77f
...
@@ -8,7 +8,7 @@ double **create_y(int steps) {
...
@@ -8,7 +8,7 @@ double **create_y(int steps) {
int
i
;
int
i
;
if
(
y
==
NULL
)
{
if
(
y
==
NULL
)
{
puts
(
"Error: could not allocate
sufficient
memory."
);
puts
(
"Error: could not allocate memory."
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -49,6 +49,9 @@ void init_plucked(double **y, int steps, double l, double dx, double xp) {
...
@@ -49,6 +49,9 @@ void init_plucked(double **y, int steps, double l, double dx, double xp) {
#define VERBOSE
#define VERBOSE
#define PRINT_FORMAT "%e"
#define PRINT_FORMAT "%e"
/*
*
*/
void
iterate
(
double
**
y
,
int
string_steps
,
double
dx
,
int
time_steps
,
double
dt
,
void
iterate
(
double
**
y
,
int
string_steps
,
double
dx
,
int
time_steps
,
double
dt
,
double
theta
)
{
double
theta
)
{
double
x
;
double
x
;
...
@@ -74,7 +77,7 @@ void iterate(double **y, int string_steps, double dx, int time_steps, double dt,
...
@@ -74,7 +77,7 @@ void iterate(double **y, int string_steps, double dx, int time_steps, double dt,
}
}
#endif
#endif
// Iterate over the length of the string
// Iterate over the length of the string
for each time interval step
for
(
t
=
2
;
t
<
time_steps
;
t
++
)
{
for
(
t
=
2
;
t
<
time_steps
;
t
++
)
{
#ifdef VERBOSE
#ifdef VERBOSE
printf
(
PRINT_FORMAT
" "
PRINT_FORMAT
" "
PRINT_FORMAT
,
t
*
dt
,
.
0
,
printf
(
PRINT_FORMAT
" "
PRINT_FORMAT
" "
PRINT_FORMAT
,
t
*
dt
,
.
0
,
...
@@ -99,21 +102,15 @@ void iterate(double **y, int string_steps, double dx, int time_steps, double dt,
...
@@ -99,21 +102,15 @@ void iterate(double **y, int string_steps, double dx, int time_steps, double dt,
current
=
next
;
current
=
next
;
next
=
(
next
+
1
)
%
3
;
next
=
(
next
+
1
)
%
3
;
}
}
// Free allocated memory
for
(
i
=
0
;
i
<
string_steps
;
i
++
)
free
(
y
[
i
]);
free
(
y
);
}
}
int
main
(
int
argc
,
const
char
**
argv
)
{
int
main
(
int
argc
,
const
char
**
argv
)
{
int
steps
;
int
steps
,
i
;
void
(
*
init_method
)(
double
**
,
int
,
double
,
double
,
double
);
void
(
*
init_method
)(
double
**
,
int
,
double
,
double
,
double
);
double
**
y
,
t
,
dt
,
l
,
dx
,
theta
,
constant
;
double
**
y
,
t
,
dt
,
l
,
dx
,
theta
,
constant
;
if
(
argc
<
8
)
{
if
(
argc
<
8
)
{
printf
(
"Usage: %s METHOD TIME DT LENGTH DX THETA N|XP
\n
"
,
argv
[
0
]);
printf
(
"Usage: %s
INIT_
METHOD TIME DT LENGTH DX THETA N|XP
\n
"
,
argv
[
0
]);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
...
@@ -134,9 +131,14 @@ int main(int argc, const char **argv) {
...
@@ -134,9 +131,14 @@ int main(int argc, const char **argv) {
constant
=
atof
(
argv
[
7
]);
constant
=
atof
(
argv
[
7
]);
y
=
create_y
(
steps
=
(
int
)
ceil
(
l
/
dx
));
y
=
create_y
(
steps
=
(
int
)
ceil
(
l
/
dx
));
(
*
init_method
)(
y
,
steps
,
l
,
dx
,
constant
);
(
*
init_method
)(
y
,
steps
,
l
,
dx
,
constant
);
iterate
(
y
,
steps
,
dx
,
(
int
)
ceil
(
t
/
dt
),
dt
,
theta
);
iterate
(
y
,
steps
,
dx
,
(
int
)
ceil
(
t
/
dt
),
dt
,
theta
);
// Free allocated memory
for
(
i
=
0
;
i
<
steps
;
i
++
)
free
(
y
[
i
]);
free
(
y
);
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
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