DEV Community

Jaipal001
Jaipal001

Posted on • Edited on

Explaining donut like 5 years old Part-1

I will explain how to write donut in any language

Let R2 = 2, R1 = 1

Image description

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;
Enter fullscreen mode Exit fullscreen mode

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;
  public singleRow(double a1, double a2, double a3) {
    this.a1 = a1;
    this.a2 = a2;
    this.a3 = a3;
  }
}
Enter fullscreen mode Exit fullscreen mode

then a matrix struct/class and make all members public

In C

typedef struct {
    singleRow a1;
    singleRow a2;
    singleRow a3;
} Matrix;
Enter fullscreen mode Exit fullscreen mode

For java

class Matrix {
  public singleRow a1;
  public singleRow a2;
  public singleRow a3;
  public Matrix(singleRow a1, singleRow a2, singleRow a3) {
    this.a1 = new singleRow(a1.a1, a1.a2, a1.a3);
    this.a2 = new singleRow(a2.a1, a2.a2, a2.a3);
    this.a3 = new singleRow(a3.a1, a3.a2, a3.a3);
  }
}
Enter fullscreen mode Exit fullscreen mode

Wait for next part

Top comments (0)