I will explain how to write donut in any language
Let R2 = 2, R1 = 1
To multply it, instead of solving in manually or a matrix solver, we will create a struct (C/C++/Go) or class (Java/Python)
In C
typedef struct {
double a1;
double a2;
double a3;
} singleRow;
Modify according to your language and make sure all members are public
For java
class singleRow {
public double a1;
public double a2;
public double a3;
}
then a matrix struct/class and make all members public
In C
typedef struct {
singleRow a1;
singleRow a2;
singleRow a3;
} Matrix;
For java
class Matrix {
public singleRow a1;
public singleRow a2;
public singleRow a3;
}
To multiply singleRow and a matrix, in C we will create a function and in Java, we will create a public static function in Matrix
singleRow multiply(singleRow m1, Matrix m2) {
singleRow res;
res.a1 = (m1.a1 * m2.a1.a1) + (m1.a2 * m2.a2.a1) + (m1.a3 * m2.a3.a1);
res.a2 = (m1.a1 * m2.a1.a2) + (m1.a2 * m2.a2.a2) + (m1.a3 * m2.a3.a2);
res.a3 = (m1.a1 * m2.a1.a3) + (m1.a2 * m2.a2.a3) + (m1.a3 * m2.a3.a3);
return res;
}
Top comments (0)