I'm creating a program in C to do the Newtow-Raphson method, it should calculate automatically for the person. However in a part of the method the automatic substitution of values in the function as for example below should be done:
f (x) = x ^ 3 - 3x -1
f (1) = 1 ^ 3 - 3.1 -1
The function the user will type as a String, and the program should take that string to replace the number in X and use as a calculation. Is there a function ready for this? I'm standing in this part, so far I have:
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <math.h>
void painelPerguntas();
double calculoQtIteracao(double raizA, double raizB, double testeParada);
double calculoModuloAB(double raizA, double raizB);
int main(){
painelPerguntas();
}
void painelPerguntas(){
double raizA = 0, raizB = 0, testeParada = 0;
printf("RAIZ [a]: ");
scanf("%lf", &raizA);
fflush(stdin);
printf("RAIZ [B]: ");
scanf("%lf", &raizB);
fflush(stdin);
printf("PARADA: ");
scanf("%lf", &testeParada);
//CALCULO QUANTIDADE DE ITERAÇÕES
calculoQtIteracao(raizA, raizB, testeParada);
double qtIteracoes = calculoQtIteracao(raizA, raizB, testeParada);
//CALCULA |A-B|
calculoModuloAB(raizA, raizB);
//CALCULA F(A).F(C)
}
double calculoQtIteracao(double raizA, double raizB, double testeParada){
double calculo = (log10(raizB - raizA) - log10(testeParada)) / log10(2);
return round(calculo);
}
double calculoModuloAB(double raizA, double raizB){
double calculo = raizA - raizB;
if(calculo < 0){
calculo = calculo * -1;
return calculo;
}else {
return calculo;
}
}
double calculoSinal(double a, double c){
double calculoA =
}