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
3f0c473f
Commit
3f0c473f
authored
Apr 05, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModSim ass3: Added early implementation of Euler method.
parent
23a5b48b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
17 deletions
+35
-17
modsim/ass3/.gitignore
modsim/ass3/.gitignore
+1
-0
modsim/ass3/Makefile
modsim/ass3/Makefile
+3
-3
modsim/ass3/methods.c
modsim/ass3/methods.c
+11
-6
modsim/ass3/methods.h
modsim/ass3/methods.h
+2
-1
modsim/ass3/test.c
modsim/ass3/test.c
+18
-7
No files found.
modsim/ass3/.gitignore
0 → 100644
View file @
3f0c473f
test
modsim/ass3/Makefile
View file @
3f0c473f
...
@@ -4,11 +4,11 @@ LFLAGS=-lm
...
@@ -4,11 +4,11 @@ LFLAGS=-lm
all
:
test
all
:
test
test
:
test.
o methods.o
test
:
test.
c methods.c
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
%.o
:
%.c
#
%.o: %.c
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
#
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
clean
:
clean
:
rm
*
.o
test
rm
*
.o
test
modsim/ass3/methods.c
View file @
3f0c473f
...
@@ -20,15 +20,20 @@ occurs (overflow, NaN or such)
...
@@ -20,15 +20,20 @@ occurs (overflow, NaN or such)
int
Euler
(
double
t0
,
double
t1
,
double
dt
,
double
*
y0
,
double
*
y1
,
int
N
,
int
Euler
(
double
t0
,
double
t1
,
double
dt
,
double
*
y0
,
double
*
y1
,
int
N
,
f_ptr
f
,
void
*
params
)
{
f_ptr
f
,
void
*
params
)
{
int
i
,
steps
=
(
int
)((
t1
-
t0
)
/
dt
+
.
5
);
int
i
;
double
slope
[
N
];
for
(
i
=
0
;
i
<
N
;
i
++
)
{
if
(
f
(
t0
,
y0
,
slope
,
params
)
)
{
puts
(
"Error calculating slope."
);
return
-
1
;
}
}
return
0
;
for
(
i
=
0
;
i
<
N
;
i
++
)
}
y1
[
i
]
=
y0
[
i
]
+
slope
[
i
]
*
dt
;
return
(
t1
-
t0
)
>
dt
?
Euler
(
t0
+
dt
,
t1
,
dt
,
y1
,
y1
,
N
,
f
,
params
)
:
0
;
}
/*
int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params) {
f_ptr f, void *params) {
...
@@ -39,4 +44,4 @@ int RungeKutta4(double t0, double t1, double dt, double *y0, double *y1, int N,
...
@@ -39,4 +44,4 @@ int RungeKutta4(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params)
f_ptr f, void *params)
return 0;
return 0;
}
}
*/
modsim/ass3/methods.h
View file @
3f0c473f
...
@@ -2,9 +2,10 @@ typedef int (*f_ptr)(double t, double *y, double *dy, void *params);
...
@@ -2,9 +2,10 @@ typedef int (*f_ptr)(double t, double *y, double *dy, void *params);
int
Euler
(
double
t0
,
double
t1
,
double
dt
,
double
*
y0
,
double
*
y1
,
int
N
,
int
Euler
(
double
t0
,
double
t1
,
double
dt
,
double
*
y0
,
double
*
y1
,
int
N
,
f_ptr
f
,
void
*
params
);
f_ptr
f
,
void
*
params
);
/*
int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params);
f_ptr f, void *params);
int RungeKutta4(double t0, double t1, double dt, double *y0, double *y1, int N,
int RungeKutta4(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params);
f_ptr f, void *params);
*/
modsim/ass3/test.c
View file @
3f0c473f
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include "methods.h"
#include "methods.h"
int
f_test_1
(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
)
{
int
f_test_1
(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
)
{
*
dy
=
1
.
0
;
*
dy
=
1
.
0
;
return
1
;
return
0
;
}
}
int
f_test_2
(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
)
{
int
f_test_3
(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
)
{
double
result
=
*
y
;
if
(
isnan
(
*
y
)
)
{
if
(
isnan
(
result
)
)
{
return
-
1
;
return
-
1
;
}
else
{
}
else
{
*
dy
=
result
;
*
dy
=
*
y
;
return
0
;
return
0
;
}
}
}
}
int
f_test_
3
(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
)
{
int
f_test_
4
(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
)
{
double
result
=
*
y
*
*
y
;
double
result
=
*
y
*
*
y
;
if
(
isnan
(
result
)
)
{
if
(
isnan
(
result
)
)
{
...
@@ -30,8 +29,20 @@ int f_test_3(double t, double *y, double *dy, void *params) {
...
@@ -30,8 +29,20 @@ int f_test_3(double t, double *y, double *dy, void *params) {
}
}
}
}
int
f_cos
(
double
t
,
double
*
y
,
double
*
dy
,
void
*
params
)
{
*
dy
=
cos
(
t
);
return
0
;
}
int
main
(
void
)
{
int
main
(
void
)
{
double
y0
[
1
]
=
{.
506
},
y1
[
1
];
if
(
Euler
(
-
100
.
0
,
10
.
0
,
0
.
001
,
y0
,
y1
,
1
,
&
f_cos
,
NULL
)
)
{
puts
(
"FAIL"
);
}
else
{
printf
(
"y1: %f
\n
"
,
*
y1
);
}
return
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