fix makefile for hw3 and add hw3/*.dat and main.c
This commit is contained in:
9
Makefile
9
Makefile
@@ -18,8 +18,8 @@ else
|
||||
LIB_SRCS := $(LIB_DIR)/recipes/machar.c
|
||||
else ifeq ($(strip $(hw)),2)
|
||||
LIB_SRCS := $(LIB_DIR)/other/nrutil.c $(LIB_DIR)/recipes/rtflsp.c $(LIB_DIR)/recipes/rtbis.c $(LIB_DIR)/recipes/rtsec.c $(LIB_DIR)/recipes/rtnewt.c $(LIB_DIR)/recipes/rtsafe.c $(LIB_DIR)/recipes/zbrak.c $(LIB_DIR)/recipes/bessj0.c $(LIB_DIR)/recipes/bessj1.c
|
||||
else
|
||||
LIB_SRCS := ""
|
||||
else ifeq ($(strip $(hw)),3)
|
||||
LIB_SRCS := $(LIB_DIR)/other/nrutil.c $(LIB_DIR)/recipes/gaussj.c $(LIB_DIR)/recipes/ludcmp.c $(LIB_DIR)/recipes/svdcmp.c $(LIB_DIR)/recipes/mprove.c $(LIB_DIR)/recipes/lubksb.c $(LIB_DIR)/recipes/pythag.c
|
||||
endif
|
||||
LIB_OBJS := $(patsubst %.c,$(BUILD_DIR)/lib/%.o,$(notdir $(LIB_SRCS)))
|
||||
|
||||
@@ -65,7 +65,10 @@ $(OBJS): %.o:
|
||||
run: clean build
|
||||
@echo "실행 시작"
|
||||
@echo "============"
|
||||
@$(TARGET_EXEC)
|
||||
@if ls $(SRC_DIR)/*.dat >/dev/null 2>&1; then \
|
||||
cp -f $(SRC_DIR)/*.dat build/; \
|
||||
fi
|
||||
@cd build && ./$(TARGET_NAME).out
|
||||
|
||||
dist: clean
|
||||
mkdir -p out
|
||||
|
||||
6
hws/hw3/lineq1.dat
Normal file
6
hws/hw3/lineq1.dat
Normal file
@@ -0,0 +1,6 @@
|
||||
4 4
|
||||
4 2 3 -1
|
||||
-2 -1 -2 2
|
||||
5 3 4 -1
|
||||
11 4 6 1
|
||||
4 -3 4 11
|
||||
7
hws/hw3/lineq2.dat
Normal file
7
hws/hw3/lineq2.dat
Normal file
@@ -0,0 +1,7 @@
|
||||
5 5
|
||||
2 -4 -5 5 0
|
||||
-1 1 2 0 4
|
||||
-1 6 0 3 2
|
||||
0 1 3 7 5
|
||||
5 0 8 7 -2
|
||||
-5 2 0 4 -1
|
||||
8
hws/hw3/lineq3.dat
Normal file
8
hws/hw3/lineq3.dat
Normal file
@@ -0,0 +1,8 @@
|
||||
6 6
|
||||
0.4 8.2 6.7 1.9 2.2 5.3
|
||||
7.8 8.3 7.7 3.3 1.9 4.8
|
||||
5.5 8.8 3.0 1.0 5.1 6.4
|
||||
5.1 5.1 3.6 5.8 5.7 4.9
|
||||
3.5 2.7 5.7 8.2 9.6 2.9
|
||||
3.0 5.3 5.6 3.5 6.8 5.7
|
||||
-2.9 -8.2 7.7 -1.0 5.7 3.0
|
||||
62
hws/hw3/main.c
Normal file
62
hws/hw3/main.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
void exit(int status) {
|
||||
static void (*real_exit)(int) = 0;
|
||||
if (!real_exit) {
|
||||
real_exit = dlsym(RTLD_NEXT, "exit");
|
||||
}
|
||||
printf("HI");
|
||||
}
|
||||
|
||||
#include "nr.h"
|
||||
#include "nrutil.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
void print_matrix(int m, int n, float **mat) {
|
||||
int i, j;
|
||||
for(i = 1; i <= m; i ++) {
|
||||
for(j = 1; j <= n; j ++) {
|
||||
printf("%6.2f ", mat[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int m, n;
|
||||
int i, j;
|
||||
FILE *fp = fopen("lineq1.dat", "r");
|
||||
|
||||
if(fp == NULL) {
|
||||
printf("Error opening file");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fscanf(fp, "%d", &m); /* row */
|
||||
fscanf(fp, "%d", &n); /* col */
|
||||
|
||||
float** a = matrix(1, m, 1, n);
|
||||
|
||||
for(i = 1;i <= m; i ++) {
|
||||
for(j = 1;j <= n; j ++) {
|
||||
fscanf(fp, "%f", &a[i][j]);
|
||||
}
|
||||
}
|
||||
float **b = matrix(1, m, 1, 1);
|
||||
for(i = 1; i<= m; i++) {
|
||||
fscanf(fp, "%f", &b[i][1]);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
print_matrix(m, n, a);
|
||||
print_matrix(m, 1, b);
|
||||
gaussj(a, n, b, m);
|
||||
print_matrix(m, n, a);
|
||||
print_matrix(m, 1, b);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user