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

Program As

This document contains code for 4 numerical methods to approximate the root of a function: Steffensen's method, Newton's method, the secant method, and the false position method. For each method, the code defines the necessary functions, sets up an iterative loop to calculate successive approximations of the root, and prints the final approximation and number of iterations.

Uploaded by

Alberto Villa
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Program As

This document contains code for 4 numerical methods to approximate the root of a function: Steffensen's method, Newton's method, the secant method, and the false position method. For each method, the code defines the necessary functions, sets up an iterative loop to calculate successive approximations of the root, and prints the final approximation and number of iterations.

Uploaded by

Alberto Villa
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

Metodo Steffensen

#include <stdio.h>
#include <math.h>
float funcion (float);
int main(){
float p0,p1, p2, p;
int i=1, Ni;
printf ("aproximacion inicial \n");
scanf("%f", &p0);
printf ("numero de iteraciones \n");
scanf("%d", &Ni);
do{
p1=funcion(p0);
p2=funcion(p1);
p=p0-(p1-p0)*(p1-p0)/(p2-2*p1+p0);
if( sqrt((p-p0)*(p-p0)) < 0.0001)
break;
i=i+1;
p0=p;
}while(i<= Ni);
printf ("la aproximacion es %f \n", p);
printf ("en la iteracion %d \n", i);
getch();
return 0;
}
float funcion(float x){
float f;
f=sqrt(1+ 1/x);
return f;
}

Metodo de Newton

#include <stdio.h>
#include <math.h>
float funcion(float);
float derivada(float);
int main(){
float p0,p;
int i;
printf ("aproximacion inicial \n");
scanf("%f", &p0);
do{
p= p0-((funcion(p0))/(derivada(p0)));
if( sqrt((p-p0)*(p-p0)) < 0.000001)
break;
i=i+1;
p0=p;
}while(i<=20);
printf ("%f \n", p);
printf ("%d \n", i);
getch();
return 0;
}
float funcion(float x){
float f;
f=230*x*x*x*x +18*x*x*x +9*x*x - 221*x-9;
return f;
}
float derivada(float x){
float d;
d=920*x*x*x +54*x*x +18*x - 221;
return d;
}

Metodo de la secante
#include <stdio.h>
#include <math.h>

float funcion(float);
int main(){
float p0, p1, p, q0, q1;
int i=2;
printf ("aproximaciones iniciales \n");
scanf("%f", &p0);
scanf("%f",&p1);
q0=funcion(p0);
q1=funcion(p1);
do{
p= p1-(q1*(p1-p0)/(q1-q0));
if( sqrt((p-p1)*(p-p1)) < 0.000001)
break;
i=i+1;
p0=p1;
q0=q1;
p1=p;
q1=funcion(p);
}while(i<=20);
printf ("%f \n", p);
printf ("%d \n", i);
getch();
return 0;
}
float funcion(float x){
float f;
f=230*x*x*x*x +18*x*x*x +9*x*x - 221*x-9;
return f;
}

Mtodo de la falsa posicin


#include <stdio.h>
#include <math.h>
float funcion(float);

int main(){
float p0, p1, p, q0, q1, q;
int i=2;
printf ("aproximaciones iniciales \n");
scanf("%f", &p0);
scanf("%f",&p1);
q0=funcion(p0);
q1=funcion(p1);
do{
p= p1-(q1*(p1-p0)/(q1-q0));
if( sqrt((p-p1)*(p-p1)) < 0.000001)
break;
i=i+1;
q=funcion(p);
if( q*q1<0){
p0=p1;
q0=q1;
}
p1=p;
q1=funcion(p);
}while(i<=20);
printf ("%f \n", p);
printf ("%d \n", i);
getch();
return 0;
}
float funcion(float x){
float f;
f=230*x*x*x*x +18*x*x*x +9*x*x - 221*x-9;
return f;
}

You might also like