I am creating a program to read a file and stores its data in an array and then create a function to compute its derivative, was able to read the files and create the derivative, but when I try to create an external function to calculate the value of derivative of the function I encounter the following error: "[error] invalid types 'double [int]' for array subscript" Ja tried to solve it in different ways, but without success.
#include "biblioteca.h"
int main(){
FILE* fp;
fp = fopen("entrada.txt","rt");
if (fp == NULL) {
printf("Erro na abertura do arquivo!\n");
exit(1); }
int i; //grau do polinomio
fscanf(fp,"%d",&i);
printf("i = [%d]\n",i);
double mat[i-1][i+1];
int c=0; //colunas
while(c<i+1){
fscanf(fp,"%lf",&mat[0][c]);
c++;
}
int h=i; //h grau do expoente
for(int l=0;l<i-1;l++){ //l linhas
int k=0; //contador
for(c=h;c>0;c--){
mat[l+1][c-1]=mat[l][c]*(h-k);
k++;
}
h--;
}
int k=0; //linhas
while(k<i){
for(c=0;c<i+1;c++){
printf("%lf \t",mat[k][c]);}
k++;
printf("\n");
}
double x=mat[i-1][0]*-1/mat[i-1][1];
printf("x = %lf\n",x);
double x1;
x1=f(**mat,i,1,x);
system("pause");
return 0;
}
library:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double f(double mat,int i,int t,double x){
double x1=0;
for(int g=0;g<i+1;g++){
if(x==0){
x1=0;
}
if(x!=0){
x1=mat[t][g]*pow(x,g)+x1;
}
}
return x1;
}
double f(double mat,int i,int t,double x){->double f(int i, double mat[i-1][i+1], int t,double x){x1=f(i, mat, 1, x);BTW whendouble x[A][B], must be 1st index < A. I seems that your code is to be often beyond the range.