如何返回矩阵? [英] How to return matrix?

查看:178
本文介绍了如何返回矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行Cramer线性求解,我写了一个函数来替换矩阵列,就像这样:

I'm trying to make a Cramer-linear-solving, and I wrote a function that replaces a matrix column, just like that:

void replacecol(int c, int n, float mat_in[n][n], float vect_in[n],
        float mat_out[n][n])
{
    int i, j;

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            if (j == c)
            {
                mat_out[i][j] = vect_in[j];
            }
            else
            {
                mat_out[i][j] = mat_in[i][j];
            }
        }
    }
}

但是它目前是空的,当我调用此函数时,我希望它返回其值为mat_out的值...我该怎么做??

But it is currently void, and I want it to return the mat_out with it's values, when I call this function... How could I do that??

推荐答案

您可以避免对函数使用2个矩阵.您可以简单地:

You can avoid to use 2 matrices for your function. You can simply:

void replacecol(int c, int n, float mat_in[n][n], float vect_in[n]))
{
    int i;

    for (i = 0; i < n; i++)
    {
        mat_in[i][c] = vect_in[i];
    }
}

float mat_in[n][c]它是指针float(*)[],因此可以在传递的矩阵上对该参数进行修改.

float mat_in[n][c] it is a pointer float(*)[] so modifications on that parameter are made on the passed matrix.

这篇关于如何返回矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆