0% found this document useful (0 votes)
45 views

Instituto Tecnológico de Leon: Factorial

This document contains code examples for numerical analysis methods including: - Factorial calculation using a for loop - False Position method to find roots of an equation - Bisection method for finding roots of a function - Secant method for finding roots of a function - Fixed Point method for finding fixed points of a function The code examples demonstrate implementing these numerical analysis techniques to solve equations and find roots numerically.

Uploaded by

Leticia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Instituto Tecnológico de Leon: Factorial

This document contains code examples for numerical analysis methods including: - Factorial calculation using a for loop - False Position method to find roots of an equation - Bisection method for finding roots of a function - Secant method for finding roots of a function - Fixed Point method for finding fixed points of a function The code examples demonstrate implementing these numerical analysis techniques to solve equations and find roots numerically.

Uploaded by

Leticia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

INSTITUTO TECNOLGICO DE LEON

ANLISIS NUMRICO

QUINTO SEMESTRE

ALUMNOS:
HERNANDEZ RAMIREZ PABLO ARMANDO
IBARRA ACOSTA JOS LUIS SALVADOR
MARTINEZ SANTAMARIA NELSON ABELARDO
SOLORIO MONTES LETICIA

FACTORIAL

#include
#include
#include
#include

<cstdlib>
<iostream>
<stdio.h>
<math.h>

int main ()
{
printf("Calcular el factorial de un numero\n");
printf("inserta un numero: \n");
float num;
scanf("%f", &num);
long fact = 1;
for(int i = 1; i <= num ; i++)
{
fact = fact*i;
}
printf("Factorial = %ld",fact);
system("PAUSE");
return EXIT_SUCCESS;
}

FALSA POSICION
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
double f(float Xi);
double f1(float Xr);
int
main(void){
int SI=1;
do{
system("cls" );
float Xi=0,Ea=0,Xz=0,Xr=0;
int cont=0;
printf("METODO DE LA SECANTE\n");
printf("introduce Xi:n\n" );
scanf("%f",&Xi);
printf("nnI Xi-1 Xi Xi+1 f(Xi-1) f(Xi) Ean" );
do{

Xr=(Xi-1);
Xz= Xi-((f(Xi)*(Xr-Xi))/(f1(Xr)-f(Xi)));
Ea=fabs((Xz-Xi)/Xz)*100;
printf("%d %f %.5f %.5f %.5f %.5f %fn",cont,Xr,Xi,Xz,f1(Xr),f(Xi),Ea);
cont++;
Xi=Xz;
}while(Ea>=0.05);
printf("nnn" );
printf("DESEAS REALIZAR LA OPERACION OTRA VEZ? SI[1] NO[2]n" );
scanf("%d",&SI);
}while(SI<=1);
system("PAUSE" );
}
double f(float Xi){
return (exp(-Xi))-Xi;
}
double f1(float Xr){
float n = (exp(-Xr))-Xr;
return n;
}

Biseccion
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main ()
{
float xi,xs,xm,e,fxi,fxs,fxm,a,b,c,d,f,p;
int i,n;
n=1;
printf("F(X)=ax^3+bx^2-cx-f\n\n");
printf("\nIntroduce
scanf("%f",&a);
printf("\nIntroduce
scanf("%f",&b);
printf("\nIntroduce
scanf("%f",&c);
printf("\nIntroduce
scanf("%f",&f);
printf("\nIntroduce
scanf("%f",&p);

el valor de a: ");
el valor de b: ");
el valor de c: ");
el valor de f: ");
el valor de p: ");

printf("\nIntroduce el valor de xi: ");


scanf("%f",&xi);
printf("\n\nIntroduce el valor de xs: ");
scanf("%f",&xs);
xm=(xi+xs)/2;
for(i=1;i<=n;i++)
{
printf("\n\nIteraccion %d",i);
fxi=(a*(xi*xi*xi))+(b*(xi*xi))-(c*(xi))-f;
fxm=(a*(xm*xm*xm))+(b*(xm*xm))-(c*(xm))-f;
fxs=(a*(xs*xs*xs))+(b*(xs*xs))-(c*(xs))-f;
printf("\n\nfxi: %.9f fxs: %.9f fxm: %.9f",fxi,fxs,fxm);
if(fxi<0 && fxm>0)
{
xi=xi;
xs=xm;
xm=(xi+xs)/2;
e=fabs((xm-xs)/xm)*100;
printf("\n\nxi: %.9f xs: %.9f xm: %.9f e: %.12f",xi,xs,xm,e);
}
if(fxi>0 && fxm<0)
{
xi=xi;
xs=xm;
xm=(xi+xs)/2;
e=fabs((xm-xi)/xm)*100;
printf("\n\nxi: %.9f xs: %.9f xm: %.9f e: %.12f",xi,xs,xm,e);
}
if(fxs<0 && fxm>0)
{
xi=xm;
xs=xs;
xm=(xi+xs)/2;
e=fabs((xm-xi)/xm)*100;
printf("\n\nxi: %.9f xs: %.9f xm: %.9f e: %.12f",xi,xs,xm,e);
}
if(fxs>0 && fxm<0)
{
xi=xm;
xs=xs;
xm=(xi+xs)/2;
e=fabs((xm-xi)/xm)*100;
printf("\n\nxi: %.9f xs: %.9f xm: %.9f e: %.12f",xi,xs,xm,e);
}
if(e>p)
n=n+1;
else
n=n-1;

}
printf("\n\nEl error es de %.12f\n\nEn la iteracion: %d\n\nLa raiz se encuentra
en: %.9f",e,i,xm);
getch ();
return 0;
SECANTE
#include<stdio.h>
#include<math.h>
#include <cstdlib>
#include <iostream>
int main (void){
float a,b,c,fun1,fun2;
float e=2.7182;
printf("\tLa funcion es : (e^-x)-x\n");
printf("Ingrese el primer valor: ");
scanf("%f", &a);
printf("Ingrese el segundo valor: ");
scanf("%f", &b);
fun1=pow(e,-a)-a;
fun2=pow(e,-b)-b;
c=(a)-(fun1*(a-b))/((fun1)-(fun2));
printf("El valor de c es %.4f\n ", c);
system("PAUSE");
return EXIT_SUCCESS;
}
PUNTO FIJO
#include<stdio.h>
#include<conio.h>
#include<math.h>
main ()
{
int i,n;
float x2,x1,x,e;
n=1;
printf("\nIntroduce el punto a: ");
scanf("%f",&x2);
printf("\nIntroduce el punto b: ");
scanf("%f",&x1);
printf("\n\nXn-2
Xn-1
Xn ");

for(i=1;i<=n;i++)
{
x=(x1)-(((x1-x2)/((pow(x1,2)-4)-(pow(x2,2)-4)))*(pow(x1,2)-4));
e=fabs((x-x1)/(x));
printf("\n%.3f
%.3f
%.3f
%.4f",x2,x1,x);
x2=x1;
x1=x;
}
getch ();
return 0;
}

You might also like