Multiplying two matrices with different dimensions

I am writing an application to multiply matrices. This works nicely as intended for matrices a and b that are nxn:

for(k = 0; k < n; k++) {
    for(i = 0; i < n; i++) {
        tmp = a[i][k];
        for(j = 0; j < n; j++) {
            c[i][j] = c[i][j] + tmp * b[k][j];
        }
    }
}

If a was nxy and b was yxm (implying c to be nxm). How would I modify the above loop to work?

Thanks

Answers


This should work:

for(k = 0; k < y; k++) {
    for(i = 0; i < n; i++) {
        tmp = a[i][k];
        for(j = 0; j < m; j++) {
            c[i][j] = c[i][j] + tmp * b[k][j];
        }
    }
}

Need Your Help

Why is AutoLayout ignoring some Contraints?

ios objective-c autolayout

The app has a simple TableView Controller that displays images on the left side. (see the first picture). The UIView is aligned to the x-axis, has a leading space constraint, and has a max width. I'd

CakePHP 2.1 Contact Form in Element Won't Send

email cakephp contact-form

I have two contact forms in my CakePHP application -- one with its own Controller, Model, and View, and another one in an element that can be accessed as a "quick" contact form from the footer of e...