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

All X Long 'Ingrese La Funcion' 'Ingrese A' 'Ingrese B' 'Ingrese N'

This document contains MATLAB code for several numerical methods: 1) Trapezoidal rule for numerical integration 2) Simpson's rule for numerical integration 3) Gauss-Seidel method for solving systems of linear equations 4) Newton-Raphson method for finding roots of equations 5) Secant method for finding roots of equations 6) False position method for finding roots of equations It also contains a function to determine if a matrix is diagonally dominant.

Uploaded by

Diego Córdoba
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)
19 views

All X Long 'Ingrese La Funcion' 'Ingrese A' 'Ingrese B' 'Ingrese N'

This document contains MATLAB code for several numerical methods: 1) Trapezoidal rule for numerical integration 2) Simpson's rule for numerical integration 3) Gauss-Seidel method for solving systems of linear equations 4) Newton-Raphson method for finding roots of equations 5) Secant method for finding roots of equations 6) False position method for finding roots of equations It also contains a function to determine if a matrix is diagonally dominant.

Uploaded by

Diego Córdoba
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/ 3

%REGLA COMPUESTA DEL TRAPECIO

clear all;
syms x;
format long;
f(x)=input('ingrese la funcion')
a=input('ingrese a')
b=input('ingrese b')
n=input('ingrese n')
h=(b-a)/n;
s=0;
for j=1:n-1;

s=s+f(a+j*h)
end
eval(h/2*(f(a)+2*s+f(b)))

%REGLA COMPUESTA DE SIMPSON


clear all;
syms x;
format long;
f(x)=input('ingrese la funcion')
a=input('ingrese a')
b=input('ingrese b')
n=input('ingrese n')

h=(b-a)/n; xi=a:h:b;
I= h/3*(f(xi(1))+2*sum(f(xi(3:2:end-
2)))+4*sum(f(xi(2:2:end)))+f(xi(end)));
eval(I)

%gauss-seidel
A=[10,-2,3,4;1,12,5,-2;0,3,6,1;4,2,1,9];
B=[5;10;15;20];
%x=[0;0;0;0]
w=1;
n=10;
D= diag(diag(A));
if(size(A,1)==size(A,2)&& det(D)~=0
L=-tril(A,-1);
U=-triu(A,-1);
for k=1:n

y=x
x=(1-w)x+w((D-L)^(-1)*U*x+(D-L)^(-1)*B)
end
max(abs(x-y))
%metodo de newton-raphson
clear all;
syms x;
format long;
f(x)=input('ingrese la funcion');
po=input('ingrese la aproximacion');
n=input('numero de interacciones');
tol=input('ingrese tolerancia');

i=1;

while i <= n
p=po-f(po)/subs(diff(f(x)),x,po);
if abs(eval(p)-po)<tol
i
eval (p)
i=n
end
i=i+1
po=p;
end

%metodo de secante
clear all;
syms x;
format long;
f(x)=input('ingrese la funcion');
po=input('ingrese la po');
p1=input('ingrese la p1')
n=input('numero de interacciones');
tol=input('ingrese tolerancia');
q1=f(p1)
q0=f(po)
i=1;
while i<=n

p=p1-(q1*(p1-po))/(q1-q0)
if abs (p-p1)<tol
i
eval(p)
i=n;
end
i=i+1
po=p1;
p1=p;
q0=q1
q1=f(p);
end
%posicion falsa
clear all;
syms x;
format long;
f(x)=input('ingrese la funcion');
po=input('ingrese la po');
p1=input('ingrese la p1')
n=input('numero de interacciones');
tol=input('ingrese tolerancia');
q1=f(p1);
q0=f(po);
i=1;
while i<=n

p=p1-(q1*(p1-po))/(q1-q0);
if abs (p-p1)<tol
i
eval(p)
i=n;
end
q=f(p)
if q*q0<0
p1=p;
q1=q;
else
po=p;
q0=q;
end
end

function
n=length(A);
kf=0;kc=0;
for i=1:n
sf=sum(abs(A(i,:)));
if(2*abs(A(i,i))>sf)
kf=kf+1;
end
sc=sum(abs(A(:,i)));
if(2*abs(A(i,i))>sc)
kc=kc+1;
end
end
if(kf==n)
disp('A es est. diag. dom. por filas')
else
disp('A NO es est. diag. dom. por filas')
end

end

You might also like