38 lines
742 B
C
38 lines
742 B
C
|
typedef struct Vector {
|
||
|
double x1;
|
||
|
double x2;
|
||
|
} Vector;
|
||
|
|
||
|
typedef struct Matrix {
|
||
|
double a11;
|
||
|
double a12;
|
||
|
double a21;
|
||
|
double a22;
|
||
|
} Matrix;
|
||
|
|
||
|
struct Matrix multiply(struct Matrix m1, struct Matrix m2) {
|
||
|
Matrix r = {
|
||
|
.a11 = m1.a11*m2.a11 + m1.a12*m2.a21,
|
||
|
.a12 = m1.a11*m2.a12 + m1.a12*m2.a22,
|
||
|
.a21 = m1.a21*m2.a11 + m1.a22*m2.a21,
|
||
|
.a22 = m1.a21*m2.a12 + m1.a22*m2.a22
|
||
|
};
|
||
|
return r;
|
||
|
};
|
||
|
|
||
|
struct Vector multiply(struct Matrix m, struct Vector v) {
|
||
|
Vector r = {
|
||
|
.x1 = (m.a11*v.x1) + (m.a12*v.x2),
|
||
|
.x2 = (m.a21*v.x1) + (m.a22*v.x2)
|
||
|
};
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
struct Vector add(struct Vector v1, struct Vector v2) {
|
||
|
Vector r = {
|
||
|
.x1 = v1.x1 + v2.x2,
|
||
|
.x2 = v1.x2 + v2.x2
|
||
|
};
|
||
|
return r;
|
||
|
}
|