Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Praktisk programmering og numeriske metoder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Lucas Christesen Ahler
Praktisk programmering og numeriske metoder
Commits
db7fd411
Commit
db7fd411
authored
4 years ago
by
Lucas Christesen Ahler
Browse files
Options
Downloads
Patches
Plain Diff
gsl-matrix exercise
parent
9b1b8a88
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
exercises/gsl-matrix/Makefile
+10
-0
10 additions, 0 deletions
exercises/gsl-matrix/Makefile
exercises/gsl-matrix/main.c
+50
-0
50 additions, 0 deletions
exercises/gsl-matrix/main.c
exercises/gsl-matrix/out.txt
+8
-0
8 additions, 0 deletions
exercises/gsl-matrix/out.txt
with
68 additions
and
0 deletions
exercises/gsl-matrix/Makefile
0 → 100644
+
10
−
0
View file @
db7fd411
CFLAGS
=
-Wall
-O1
-std
=
gnu11
CFLAGS
+=
$(
shell /usr/bin/gsl-config
--cflags
)
LDLIBS
+=
$(
shell /usr/bin/gsl-config
--libs
)
default
:
main
./
$<
>
out.txt
.PHONEY
:
clean
clean
:
$(
RM
)
main out.txt
\ No newline at end of file
This diff is collapsed.
Click to expand it.
exercises/gsl-matrix/main.c
0 → 100644
+
50
−
0
View file @
db7fd411
#include
<stdio.h>
#include
<gsl/gsl_vector.h>
#include
<gsl/gsl_matrix.h>
#include
<gsl/gsl_blas.h>
#include
<gsl/gsl_linalg.h>
#define RND (double)rand()/RAND_MAX
void
print_vector
(
char
s
[],
gsl_vector
*
v
)
{
printf
(
"%s
\n
"
,
s
);
for
(
int
i
=
0
;
i
<
v
->
size
;
i
++
)
{
printf
(
"%15g"
,
gsl_vector_get
(
v
,
i
));
printf
(
"
\n
"
);
}
}
int
main
(){
int
n
=
3
;
gsl_matrix
*
A
=
gsl_matrix_alloc
(
n
,
n
);
gsl_matrix
*
Acopy
=
gsl_matrix_alloc
(
n
,
n
);
gsl_vector
*
x
=
gsl_vector_alloc
(
n
);
gsl_vector
*
b
=
gsl_vector_alloc
(
n
);
gsl_vector
*
y
=
gsl_vector_calloc
(
n
);
gsl_matrix_set
(
A
,
0
,
0
,
6
.
13
);
gsl_matrix_set
(
A
,
0
,
1
,
8
.
08
);
gsl_matrix_set
(
A
,
0
,
2
,
-
4
.
36
);
gsl_matrix_set
(
A
,
1
,
0
,
-
2
.
90
);
gsl_matrix_set
(
A
,
1
,
1
,
-
6
.
31
);
gsl_matrix_set
(
A
,
1
,
2
,
1
.
00
);
gsl_matrix_set
(
A
,
2
,
0
,
5
.
86
);
gsl_matrix_set
(
A
,
2
,
1
,
-
3
.
89
);
gsl_matrix_set
(
A
,
2
,
2
,
0
.
19
);
gsl_matrix_memcpy
(
Acopy
,
A
);
gsl_vector_set
(
b
,
0
,
6
.
23
);
gsl_vector_set
(
b
,
1
,
5
.
37
);
gsl_vector_set
(
b
,
2
,
2
.
29
);
gsl_linalg_HH_solve
(
Acopy
,
b
,
x
);
gsl_blas_dgemv
(
CblasNoTrans
,
1
,
A
,
x
,
0
,
y
);
print_vector
(
"Right hand side is:"
,
b
);
print_vector
(
"Check A*x should be equal b:"
,
y
);
gsl_matrix_free
(
A
);
gsl_matrix_free
(
Acopy
);
gsl_vector_free
(
x
);
gsl_vector_free
(
b
);
gsl_vector_free
(
y
);
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
exercises/gsl-matrix/out.txt
0 → 100644
+
8
−
0
View file @
db7fd411
Right hand side is:
6.23
5.37
2.29
Check A*x should be equal b:
6.23
5.37
2.29
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