how do I read any math function?

0

Hi, I've been doing a program for a subject that is numerical calculation and based on a topic called error analysis, that theme has very basic formulas and are developed by mathematical functions such as: cos (x) + x- 2, sin (x) -x ^ 2 + 1, tan (x) + sin (x) -log2 (x) -1 and so on, I made this program especially for a function that you will see below but I would like the user I will enter the function with which I want the program to do the process of formulas and iterations. the epsilon that is the "e" will have a value of 0.01 and is where the process has to be done until the values are less than the, the x that is what they go in the functions is entered by the user with a condition that is greater than zero and less than 1 and the formulas of this method that grip are the following:

Vv(error verdadero)= aproximacion - error
ER(error relativo)= Ev/Vv
ER%= Ev/Vv*100%
EA(error aproximado)= error/valor aprox.
EA%= ((aprox. actual-aprox. anterior)/aprox. actual)*100%
|EA|<e

These are the formulas that the program does but I would like the user to place the function and to give the value to x for the program to do the process but I do not know how to read it for various mathematical functions.

#include <iostream>
#include <math.h>
#include <windows.h>
using namespace std;
#define e 0.01
void fn(float a);
int fact(int b);
int cnt=0;
int main(){
float x;
do{
    cout<<"Introduzca el valor de X para la funcion:"<<endl; cnt++;
    cout<<"(e^X)=1+X+((X^2)/2!)+...+((X^n)/n!)"<<endl; cnt++;
    cin>>x;
    cout<<endl; cnt++;
    if(x<0||x>=1){
        cout<<"X debe ser mayor a 0 menor a 1"<<endl; cnt++;
    }
    else{
        fn(x);
    }
}while(x<0||x>=1);
return 0;
}
void fn(float a){
int i=1;
double an=1, aa=0, vv=(pow(M_E,a)), ER=0, EA=0, EV;
do{
    EV=vv-an;
    ER=((EV/vv)*100);
    EA=((an-aa)/an)*100;
    aa=an;
    cout<<pow(a,i)<<"\t"<<fact(i)<<endl;
    an=an+((pow(a,i))/fact(i));
    cout<<i-1<<":\nError Relativo: "<<ER<<"\nError Absoluto: "<<EA<<"\nValor 
    Aproximado: "<<an<<"\nError Verdadero: "<<EV<<endl;
    i++;
    cout<<endl;
    Sleep(1000);
    }while(EA>e);
    system("pause");
    system("cls");
    cout<<"Valor Verdadero: "<<pow(M_E,a)<<endl;
    cout<<"Valor Aproximado: "<<an<<endl;
    cout<<"Error Verdadero: "<<EV<<endl;
    cout<<"Error Relativo: "<<ER<<endl;
    cout<<"Error Absoluto: "<<EA<<endl;
  }

int fact(int b){
if(b==0){
    return (1);
}
else{
    return ((b*fact(b-1)));
}
}
    
asked by Joni 04.11.2018 в 01:50
source

0 answers