如何将变量从 Octave 传递给 c?

问题描述 投票:0回答:0

在下面的程序中,通过Octave计算c中的行列式。但我不知道如何将变量从八度传递给 c:

#include <stdio.h>


int main(void)
{ 
    FILE *graf;
    graf=popen("octave -persist","w");
    if (graf==NULL)
        printf("Error \n");
    else
    { 
        int a;
 printf("input the dimension: /n");
 scanf("%d",&a);
 fprintf(graf,"N= %d;",a);
 fprintf(graf,"pkg load statistics \n");
 fprintf(graf,"M=N-1;");
 fprintf(graf," for i=1:%d \n",a);
 fprintf(graf," for j=1:%d \n",a);
 fprintf(graf," matriz(i,j)=round(1+9*rand());");
 fprintf(graf," endfor \n");
 fprintf(graf,"endfor \n");
 fprintf(graf,"C = combnk(1:%d,M);",a);
 fprintf(graf,"Combinaciones=size(C,1);");
 fprintf(graf,"for i=1:Combinaciones \n");
 fprintf(graf,"for j=1:Combinaciones \n");
 fprintf(graf,"for h=1:M \n");
 fprintf(graf,"for k=1:M \n");
 fprintf(graf,"matrices(h,k)=matriz(C(i,h),C(j,k));");
 fprintf(graf,"endfor \n");
 fprintf(graf,"endfor \n");
 fprintf(graf,"nuevamatriz(Combinaciones-i+1,Combinaciones-j+1)=det(matrices);");
 fprintf(graf,"endfor \n");
 fprintf(graf,"endfor \n");
 fprintf(graf,"matriz \n");
 fprintf(graf,"det(matriz) \n");
 fprintf(graf,"nuevamatriz \n");
 fprintf(graf,"det(nuevamatriz) \n");
pclose(graf);
        pclose(graf);
    }
printf("Have that the second determinant (attached matrix) is always the first (matrix) powered at dimension less one \n\n ");
}

一种在c中定义这个决定变量的方法

c math octave
© www.soinside.com 2019 - 2024. All rights reserved.