Está en la página 1de 4

Derivacion.

namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int i, imax=0, n; double error, y, x, h, emax; n = 30; x = 0.5; h = 1; emax = 0; for (i = 1; i <= n; i++) { h=.25*h; y=(f(x+h)-f(x))/h; error = df(x - y); Console.WriteLine("i{0}h{1}error{2}",i,h,error); if(error>emax) { emax= error; imax=i; }

} Console.WriteLine("imax{0} emax{1}",imax,emax); Console.ReadLine();}

static double f(double x) { return Math.Sin(x); } static double df(double x) { return Math.Abs(Math.Cos(x)); } } }

Integracion Suma de inferiores y superiores


namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int i; double h,suma,sumainferior,sumasuperior,x; int n=50; double a=0, b=.8; h=(b-a)/n; suma=0; for(i=n;i>=1;i--) {

x=a + i*h; suma+= funcion(x); Console.WriteLine(i); } sumainferior= suma*h; sumasuperior= sumainferior+h*(funcion(a)-funcion(b)); Console.WriteLine("sumainferior{0}, sumasuperior{1}",sumainferior,sumasuperior); Console.ReadLine();

} static double funcion(double x) { return /*return (.2 + 25 * x - 200 * Math.Pow(x, 2) + 675 * Math.Pow(x, 3) - 900 * Math.Pow(x, 4) + 400 * Math.Pow(x, 5));*/ /*return Math.Exp(-Math.Pow(x,2));*/ } } }

Regla del trapecio


namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int i; double h, suma, x; int n = 60; double a = 0, b = 1; h = (b - a) / n; suma = .5 * (funcion(a) - funcion(b)); for (i = 1; i <= n-1; i++) { x = a + i * h; suma += funcion(x);

} suma *= h; Console.WriteLine(suma); Console.ReadLine();

} static double funcion(double x) {

/*return (.2 + 25 * x - 200 * Math.Pow(x, 2) + 675 * Math.Pow(x, 3) 900 * Math.Pow(x, 4) + 400 * Math.Pow(x, 5));*/ return Math.Exp(-Math.Pow(x, 2)); } } }

int i; double h, suma, x; int n = 60; double a = 0, b = 1; h = (b - a) / n; suma = 0.5 * (funcion(a) - funcion(b)); for (i = 1; i <= n-1 ; i++) { x = a + i * h; suma += funcion(x); } suma *= h; Console.WriteLine(suma); Console.ReadLine();

Metodo De Simpson
namespace ConsoleApplication1 { class Program { static void Main(string[] args) {

int i=0; double h=0, suma=0, x=0; int n = 50; double a, b; Console.WriteLine("deme los valores de integracion"); a=Convert.ToDouble( Console.ReadLine()); b = Convert.ToDouble(Console.ReadLine()); h = (b - a) / n; suma=0; i=0; for(i=0;i<=n;i++) { x = a + i * h; if (i == 0 || (i == n)) suma += funcion(x); else

if ((i % 2) != 0) suma += 4 * funcion(x); else suma += 2 * funcion(x); } Console.WriteLine(suma * h / 3); Console.ReadLine(); } static double funcion(double x) { return (.2 + 25 * x - 200 * Math.Pow(x, 2) + 675 * Math.Pow(x, 3) - 900 * Math.Pow(x, 4) + 400 * Math.Pow(x, 5)); /*return Math.Exp(-Math.Pow(x, 2));*/ /* return x / (Math.Sqrt(1 + Math.Pow(x, 2)));*/ } } }