- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
int main(){
int f,d;
float** a1, **a2,**p,**t;
read_from_file(a1,a2);
/*DEBUG PRINT AGAIN MATRIX A1 */
for(f = 0; f<4; f++)
for(d = 0; d<4; d++)
printf("a[%d][%d] = %f\n",f,d,a1[f][d]);
}
void read_from_file(float** a, float** b){
a = my_malloc(4,4);
b = my_malloc(4,4);
int temp;
FILE* fd;
fd = fopen("matrici.txt","r");
if(fd == NULL){
perror("errore opening file\n");
exit(1);
}
int i,j;
for(i=0; i<4; i++)
for(j=0; j<4; j++){
fscanf(fd,"%d", &temp);
a[i][j]= (float)temp;
}
for(i=0; i<4; i++)
for(j=0; j<4; j++){
fscanf(fd,"%d", &temp);
b[i][j]= (float)temp;
}
fclose(fd);
/* DEBUG PRINT MATRIX "A1" */
for(i = 0; i<4; i++)
for(j = 0; j<4; j++)
printf("a[%d][%d] = %f\n",i,j,a[i][j]);
}
好吧大家好,当我编写一个程序时,该程序必须从文件中读取一些浮点值并将它们存储到该矩阵中,出现了一个常见的错误:当我在“从文件读取”函数中打印矩阵时,存储在其中的值是:
a[0][0] = 3.000000
a[0][1] = 1.000000
a[0][2] = -1.000000
a[0][3] = 0.000000
a[1][0] = 0.000000
a[1][1] = 7.000000
a[1][2] = -3.000000
a[1][3] = 0.000000
a[2][0] = 0.000000
a[2][1] = -3.000000
a[2][2] = 9.000000
a[2][3] = -2.000000
a[3][0] = 0.000000
a[3][1] = 0.000000
a[3][2] = 4.000000
a[3][3] = -10.000000
但是当我在主函数中再次打印相同的矩阵时(在调用 read_from_file 之后),存储在其中的值是:
a[0][0] = 53806348.000000
a[0][1] = 14144784983268524032.000000
a[0][2] = 208613343232.000000
a[0][3] = 15659650322576441344.000000
a[1][0] = 13841544192.000000
a[1][1] = 0.048908
a[1][2] = 71857615689329949954782789632.000000
a[1][3] = 202218044416841482240.000000
a[2][0] = 3664429973504.000000
a[2][1] = 15151608880334635008.000000
a[2][2] = 234149008.000000
a[2][3] = 55906620.000000
a[3][0] = 14358698268987228160.000000
a[3][1] = 3157.142334
a[3][2] = 15151608880334635008.000000
a[3][3] = 13.265934
感谢您的帮助:)
最佳答案
函数的参数是其局部变量。您可以想象按以下方式调用函数 read_from_file
及其定义
float** a1, **a2,**p,**t;
read_from_file(a1,a2);
//...
void read_from_file( /*float** a, float** b */){
float **a = a1;
float **b = a2;
a = my_malloc(4,4);
b = my_malloc(4,4);
//...
因此,在函数内,原始参数 a1
和 b1
不会更改。该函数处理原始参数值的副本。
如果您想在函数内更改参数,则应该通过引用间接通过指针传递参数。
例如
float** a1, **a2,**p,**t;
read_from_file( &a1, &a2 );
//...
void read_from_file( float ***a, float ***b){
*a = my_malloc(4,4);
*b = my_malloc(4,4);
//...
关于C语言: bug = different matrix values when i print it in the main function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49068672/
问题来自 Julia Discourse 我正在使用 Julia 1.2。这是我的测试: a = rand(1000, 1000) b = adjoint(a) c = copy(b) @btime
给定两个 m x n 矩阵 A 和 B,其元素属于集合 S。 问题:A 的行和列可以置换为 B 吗? 解决这个问题的算法的复杂度是多少? 行列式有部分帮助(当 m=n 时):必要条件是 det(A)
这是共同计算平移和旋转的正确方法,还是有更好的方法?目前我的代码先翻译然后旋转,这会造成问题吗? 代码 from math import cos, sin, radians def trig(angl
如何在 core.matrix 中将矩阵和向量元素相乘? 我正在尝试找到与以下 Octave 音程代码等效的 core.matrix: A = [1 2 3 4; 5 6 7 8] B = [2; 3
我是 Scilab 的新用户(另见 here)。 我定义了一个简单的分段函数,并在使用该函数 ( "Warning adding a matrix with the empty matrix will
我有一个像这样的 RDD: (A,AA,1) (A,BB,0) (A,CC,0) (B,AA,2) (B,BB,1) (B,CC,4) 我想将其转换为以下 RRD: ([1,0,0],[2,1,4])
我使用的矩阵如下 (require '[clojure.core.matrix :as ccm]) (def M (ccm/matrix [[1 2] [3 4]])) (ccm/mset! M 0
我有一个矩阵类,它有一组函数,其中一个是矩阵运算符++(); 构造函数: Matrix(int num_rows,int num_col,int initialization,double initi
我有一个矩阵如下; 1 2 3 4 5 1 0 1 1 0 0 2 0 0 1 1 0 3 1 0 0 0 1 4 0 0 1 0 0
我已经部署了为家庭服务器(synapse)运行的单个实例,并附加了多个域作为 example.com 和 example1.com。我想创建像 [email protected] 这样的用户和 [em
我有 200 个向量;每一个的长度都是 10000。 我想填充一个矩阵,使每一行代表一个向量。 最佳答案 如果你的向量已经存储在一个数组中,那么你可以在这里使用 vcat( ): A = [rand(
如何向现有矩阵添加行或列?我正在尝试添加一个偏差项(一列)作为矩阵的第一行。在 Octave 中我可以这样做: M = [ones(size(M, 1), 1), M]; 最佳答案 您可以使用 joi
我正在使用 GNU GSL 进行一些矩阵计算。我正在尝试将矩阵 B 与矩阵 A 的逆矩阵相乘。 现在我注意到 GSL 的 BLAS 部分有一个函数可以做到这一点,但前提是 A 是三角形。这有什么具体原
我想计算如下:Matrix * Matrix Matrix有大约 6M*3 个元素,如何转换 Matrix至 Matrix这样我就能得到 Matrix结果。 最佳答案 您可以使用 Map 函数将 do
我只是没有看到我的错误。关于此错误消息的问题太多了,答案要么不适用,要么我只是看不到它们适用。也许应该改进错误消息? Matrix a = Matrix(3, 4); // fill a with v
在android.opengl.Matrix类中有两种旋转矩阵的方法,它们是: static void rotateM (float[] m, int mOffset, float a, float
我正在使用 C++ 进行编码,并且使用的是 FEniCS fenics/2016.1.0。我的部分代码是 Matrix A; Vector f; std::vector> dirichlet_matr
JAMA(用于矩阵计算的 java 库)中的 JAMA:Matrix.times() 与 Matrix.arrayTimes() 有什么区别 如果我有一个d维度 vector x和一个k维度 vect
我试图做的是简单地将 cublasDgemm(矩阵-矩阵乘法)应用于多个具有“双”(8 字节)类型元素的矩阵,所有这些元素都具有一个非常大的维度。在我的例子中,矩阵的大小是 12755046 x 46
我正在尝试使用 android Matrix 对象旋转给定的位图。 我想将它发送到我的服务器,我正在使用 Android API8。 我应该使用 Matrix.setRotate 还是 Matrix.
我是一名优秀的程序员,十分优秀!