Professional Documents
Culture Documents
Programs
Programs
clc,clear all
%cordenadas de los nodos
cord=[0 0;75 75;75 0;150 75;150 0;225 75;225 0;300 75;300 0;375 75;375
0;450 75;450 0;525 75;525 0;600 0];
%relacion de las barras con los nodos
barr=[1 2 ;2 3;3 1;2 4;4 5;2 5;3 5;4 6;6 7;4 7;5 7;7 9;6 9;8 9;6 8;8 10;9
10;9 11;10 11;10 12;11 12;11 13;12 13;11 13;12 14;13 14;14 15;13 15;15
16;14 16];
%vector para enumerar las barras
nbar=[37.5 37.5;37.5 0;75 37.5;112.5 75;112.5 37.5;112.5 0;150 37.5;187.5
75;187.5 37.5;187.5 0;225 37.5;262.5 75;262.5 37.5;262.5 0;300 37.5;337.5
75;
337.5 37.5;337.5 0;375 37.5;412.5 75;412.5 37.5;412.5 0;450
37.5;487.5 75;487.5 37.5;487.5 0;525 37.5;562.5 37.5;562.5 0];
%grafica
axis([-75 675 -75 150])
figure (1);
plot(cord(:,1),cord(:,2),'.b', 'MarkerSize', 28);
axis([-75 675 -75 150])
grid on
hold on
title('PUENTE TIPO PRATT');
xlabel('base en (cm)');
ylabel('altura en (cm)');
for k=1:size(barr,1)
X(2*k-1,1)=barr(k,1);
X(2*k,1)=barr(k,2);
end
for k=1:size(X,1)
P(k,1)=cord(X(k,1),1);
P(k,2)=cord(X(k,1),2);
end
plot(P(:,1),P(:,2),'-r','LineWidth', 1.5)
hold on
%numero de nodos
for k=1:size(cord,1)
a=int2str(k);
text (cord(k,1)+3, cord(k,2)+3, a)
end
%numero de barras
for k=1:size(nbar,1)
a=int2str(k);
text (nbar(k,1)+3,nbar(k,2)+3, a,'color','b')
end
format long
a=input('valor de la base: ');
b=input('valor de la altura: ');
c=sqrt(a^2+b^2);
sin=b/c;
cos=a/c;
A= [
1 0 cos 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 sin 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 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000;0;-1500;0;0;0;-1000;0;500000;0;-500;0;0;0;100000];
D=inv(A)*(-F);
disp('LAS FUERZAS EN LAS BARRAS SON: ')
fprintf('\n F1:%f \n F2:%f \n F3:%f \n F7:%f \n F4:%f \n F5:%f \n F6:%f
\n F9:%f \n F8:%f \n F10:%f \n F15:%f \n F13:%f \n F12:%f \n F11:%f \n
F14:%f \n F17:%f \n F16:%f \n F18:%f \n F19:%f \n F20:%f \n F24:%f \n
F21:%f \n F22:%f \n F23:%f \n F27:%f \n F25:%f \n F26:%f \n F29:%f \n
F28:%f \n F30:%f \n F31:%f \n F32:%f \n',D)
X= -10:0.01:10;
Y = f(X);
plot(X,Y)
grid on
xa = input('Ingresa El Valor Inferior: ');
xb = input('Ingresa El Valor Superior: ');
T = input('Ingresa La Tolerancia Deseada: ');
vc = 0; N = 0; E = 100;
while ( E > T)
vc = ((xa*f(xb))-(xb*f(xa)))/(f(xb)-f(xa));
if ((f(xa))*(f(vc)) < 0)
xb = vc;
else xa = vc;
end
E = abs(f(vc));
N = N+1;
end
fprintf('Resultado: \n\t%.20f\n',vc)
%MÉTODO DE LA SECANTE
%'log(3*x)+sin(2*x+1)'
clc; clear;
fc = input('Ingrese La Función: ');
f = inline(fc);
x0 = input('Ingrese El Valor Inferior: ');
x1 = input('Ingrese El Valor Superior: ');
T= input('Ingrese La Tolerancia: ');
E = 100;
n = 0;
while (E > T)
x2 = x1-(x1-x0)*f(x1)/(f(x1)-f(x0));
E = abs(f(x2));
x0 = x1;
x1 = x2;
n = n+1;
end
fprintf('Resultado: %.20f\t\t\n',x2)
%METODO DE BISECCION
%'x^3+2*x^2+10*x-20'
clc; clear;
H = input('Ingrese La Función A Analizar: ');
F = inline(H);
A = input('Ingrese El Límite Inferior: ');
B = input('Ingrese El Límite Superior: ');
T = input('Tolerancia Deseada: ');
C = 0; N = 0; M = (B-A)/2;
while (M > T)
C = (A + B)/2;
if ((F(A)*F(C)) <= 0)
B = C;
else A = C;
end
M = (B-A)/2;
N = N+1;
end
fprintf('Resultado: \n\t%.10f\n',C)
%OBTENER X
for i=n:-1:1
x(i)=a(i,n+1);
for j=i+1:n
x(i)= x(i)-x(j)*a(i,j);
end
x(i)=x(i)/a(i,i);
end
%MÉTODO DESCOMPOSICIÓN LU
clc,clear;
a=6;
b=9;
c=sqrt(a^2+b^2);
sin=b/c;
cos=a/c;
A=input('ingrese su matriz cadrada: ');
b=input('ingrese el vector de constantes: ');
orden1=size(A);n=orden1(1,1);L=eye(n);U=zeros(n);
for j=1:n
U(1,j)=A(1,j);
end
for i=2:n
L(i,1)=A(i,1)/U(1,1);
end
for i=2:(n-1)
for j=i:n
sum=0;
for k=1:(i-1)
sum=sum+L(i,k)*U(k,j);
end
U(i,j)=A(i,j)-sum;
clear sum
end
end
for j=2:(n-1)
for i=j+1:n
sum=0;
for k=1:(j-1)
sum=sum+L(i,k)*U(k,j);
end
L(i,j)=(A(i,j)-sum)/U(j,j);
clear sum
end
end
sum=0;
for k=1:(n-1)
sum=sum+L(n,k)*U(k,n);
end
U(n,n)=A(n,n)-sum;
z=inv(L)*b;
z;
x=inv(U)*z;
A
L
U
LxU=L*U
x
%Cholesky(A)
%A debe De Ser Simétrica
%Su Diagonal Debe De Ser Dominante
function x = Cholesky(A)
[m n] = size(A);
if m~= n
error('La Matriz A Debe De Ser Cuadrada Y Simétrica');
end
b = [sum(A(1,:)); sum(A(2,:)); sum(A(3,:))];
U = chol(A);
disp('U= '); disp(U)
d = U\b;
x = U\d;
disp('x= '); disp(x)
%FACTORIZACION LU
clc; clear;
end
D=A
% para la creacion de las matrices U y L
[n n]=size(A);
for k=1:n
L(k,k)=1;
for i=k+1:n
L(i,k)=A(i,k)/A(k,k);
for j=k+1:n
A(i,j)=A(i,j)-L(i,k)*A(k,j);
end
end
for j=k:n
U(k,j)=A(k,j);
end
end
U
L
% introduccion del vector de coeficientes
disp('Lectura del vector columna B')
for i=1:n
fprintf('Ingrese el valor para Y(%d):',i)
B(i)=input('');
end
B
[n n]=size(L);
L=[L B']
y=zeros(n,1);
y(1)=L(1,n+1)/L(1,1);
for i=2:n
s=0;
for j=1:n-1
s=s+L(i,j)*y(j);
end
y(i)=(L(i,n+1)-s)/L(i,i);
end
y
Y=y;
%function x=susta(A,B)
[n n]=size(U);
U=[U Y]
for i=n:-1:1
X(i)=U(i,n+1);
for j=i+1:n
X(i)=X(i)-X(j)*U(i,j);
end
X(i)=X(i)/U(i,i);
end
X'
%GAUSS
clc; clear;
n=input('¿De cuentos elemento se compone el sistma?: ');
%Reservamos espacio anticipadamente para obtimizar.
M=zeros(n,n); Y=zeros(n,1); X=Y;
%Lectura de la matriz de coeficientes.
disp('Lectura de la matriz de coeficientes')
for i=1:n
for j=1:n
fprintf('Ingrese el valor para M(%d,%d):',i,j)
M(i,j)=input('');
end
end
disp('Lectura del vector columna Y')
for i=1:n
fprintf('Ingrese el valor para Y(%d):',i)
Y(i)=input('');
end
%Forma de la matriz ampliada
A=[M,Y];
B=A;
%Eliminacion hacia adelante
for j=1:n-1
for i=j+1:n
A(i,:)=A(i,:)+A(j,:)*(-A(i,j)/A(j,j));
end
end
%sustitucion hacia atras
for i=n:-1:1
X(i)=A(i,n+1);
for j=i+1:n
X(i)=X(i)-X(j)*A(i,j);
end
X(i)=X(i)/A(i,i);
end
M
Y
B
A
disp('Se ha encontrado el valor de las incognitas')
X
%JACCOBI
clear all
clc
n=input('Numero de ecuaciones(n):');
A=input('introdusca la matriz A:');
b=input('introdusca el vector b,vector columna:');
n=input('Numero maximo de interacciones(m):');
E=input('Error permitido (valor de la norma):');
Xo=zeros(1,n);
X=Xo;
K=0;
Norma=1;
while Norma>E
K=K+1;
fprintf('%d',K);
for i=1:n
suma=0;
for j=1:n
if i~=j
suma=suma+A(i,j)*X(j);
end
end
X(i)=(b(i)-suma)/A(i,i);
fprintf('%10.6f',X(i));
end
Norma=norm(Xo-X);
fprint('%10.6f\n',Norma);
X0=X;
if K>m
break
end
end
%SELTI
%%Sustitucion de matriz triangular inferior
%A matriz de coeficientes triangular inferior
%B matriz en forma de vector de vales
%para poeder correr la funcion es necsesario antes intoducior los valores
de A y B
function x=selti(A,B)
[n n]=size(A);
A=[A B']
x=zeros(n,1);
x(1)=A(1,n+1)/A(1,1);
for i=2:n
s=0;
for j=1:n-1
s=s+A(i,j)*x(j);
end
x(i)=(A(i,n+1)-s)/A(i,i);
end
x
%% sustitucion de
mariz tiangular
superior
%A matrisz de coeficientes
%B vector columna con valores de las ecuaciones.
%para poder obtener el despeje de los valores correspondientes para las
%incognitas sera besezario que la matriz A sea una matris triagular
%superior es decir que por debajo de su diagonal principal contenga
ceros.
%valores de salida X fila de valores corespondientes para las incognitas
function x=susta(A,B)
[n n]=size(A);
A=[A B]
for i=n:-1:1
X(i)=A(i,n+1);
for j=i+1:n
X(i)=X(i)-X(j)*A(i,j);
end
X(i)=X(i)/A(i,i);
end