我有这段代码假设对两个向量进行 daxpy 操作并输出结果,但是当我运行它时它给了我 3 个 4(我认为它假设给了我 3 个 6)。
我觉得好像我错过了关于 daxpy 的一些重要的东西,但我不知道它是什么。
这是代码:
#include <iostream>
using namespace std;
extern "C"
{
double daxpy_(double *A, double *B, int *n, double *a);
//The daxpy fortran function shown above multiplies a first matrix 'A' by a constant 'a'
//and adds the result to a second matrix 'B.' Both matrices are of size 'n.'
}
void daxpy(double *A, double *B, int n, double a);
//The function above is declared in order to utilize c-notation to perform the fortran
//daxpy function which takes a first matrix 'A' and multiplies the matrix by a costant 'a'
//and then adds the result to a second matrix 'B.'
int main(int argc, char *argv[])
{
double A[3], B[3];
int n=3;
double a=1.0;
for (int i=0;i<3;i++)
{
A[i]=2;
B[i]=4;
}
daxpy(A, B, n, a);
for (int i=0;i<3;i++)
{
cout << B[i] << endl;
}
}
void daxpy(double *A, double *B, int n, double a)
{
for (int i=0;i<n;i++)
{
B[i]=daxpy_(A, B, &n, &a);
}
}