Codigo de Matlab Proyecto Vibraciones

Codigo de matlab: *Yo lo imprimo bn con colorcitos luego pero pa que vayas diciendo q códigos se usaron y los pegues usa

Views 57 Downloads 2 File size 223KB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

Codigo de matlab: *Yo lo imprimo bn con colorcitos luego pero pa que vayas diciendo q códigos se usaron y los pegues usa esto… FUNCION DE LUIS(se llama exitacion, yo le cambie el nombre, esta hace la función exitacion y la guarda en un vector) function [ Y ] = exitacion( X ) R = 0; for i=1:length(X) if X(i) > 40 break end Y(i)=0.2*X(i)^2/80 - R; if Y(i) >= 0.2 R = R + Y(i); end end R = 0; for i=1:length(X) if X(i) < 40 continue end Y(i) = 0.2*(X(i)-40) - R; if Y(i) >= 0.2 R = R + Y(i); end end end

PROYECTO(este es el codigo completo que llama a esa función, aquí se grafica el vector de la función exitacion se hacen los RK4 se grafica pos tiempo y vel tiempo y espectro… primero hace todo eso para el amortiguado y luego hace todo eso para el no amortiguado) clc clear all close all tiempo = 0:0.01:200; desplazamiento = exitacion(tiempo); plot(tiempo,desplazamiento); title('Funcion de exitacion') xlabel('tiempo') ylabel('Desplazamiento Zt') % RK4

%RK4 para factor de amortiguacion 0.02 h = 0.01; Pos_0=0; Vel_0=0; z1_0=Pos_0; z2_0=Vel_0; f1 = inline('z2','Zt','z1','z2'); f2 = inline('(15*Zt)-20*z1-2*sqrt(5)*0.02*z2','Zt','z1','z2'); z1=z1_0; z2=z2_0; disp(' Zt Pos Vel') Zt=0 for i=1:length(tiempo) k11=f1(Zt,z1,z2); k12=f2(Zt,z1,z2); k21=f1(Zt+h/2,z1+k11*h/2,z2+k12*h/2); k22=f2(Zt+h/2,z1+k11*h/2,z2+k12*h/2); k31=f1(Zt+h/2,z1+k21*h/2,z2+k22*h/2); k32=f2(Zt+h/2,z1+k21*h/2,z2+k22*h/2); k41=f1(Zt+h,z1+k31*h,z2+k32*h); k42=f2(Zt+h,z1+k31*h,z2+k32*h); z1=z1+(k11+2*k21+2*k31+k41)*h/6; z2=z2+(k12+2*k22+2*k32+k42)*h/6; Zt=desplazamiento(i); disp([Zt,z1,z2]) X1(i)=z1; V1(i)=z2; end figure plot(tiempo,X1) title('Grafico Posición vs tiempo (amortiguado)') xlabel('tiempo') ylabel('Posición') figure plot(tiempo,V1) title('Grafico Velocidad vs tiempo (amortiguado)') xlabel('tiempo') ylabel('Velocidad') %espectro para factor de amortiguacion 0.02 tiempoesp=100:0.01:200; Fs = 1; % frecuencia T = 1/Fs; % periodo L = length(tiempoesp); % tiempo de la senal t = tiempoesp; %(0:L-1)*T; % vector tiempo % amplitudes x = X1(100:200); NFFT = 2^nextpow2(L); Y = fft(x,NFFT)/L; f = Fs/2*linspace(0,1,NFFT/2+1); figure plot(f,2*abs(Y(1:NFFT/2+1)))

title('Espectro de frecuencias fac de amortiguacion 0.02') xlabel('Frecuencia (Hz)') ylabel('|Y(f)|') %RK4 para factor de amortiguacion 0 (sin amortiguacion) h = 0.01; Pos_0=0; Vel_0=0; z1_0=Pos_0; z2_0=Vel_0; f1 = inline('z2','Zt','z1','z2'); f2 = inline('(15*Zt)-20*z1-2*sqrt(5)*0*z2','Zt','z1','z2'); z1=z1_0; z2=z2_0; disp(' Zt Pos Vel') Zt=0 for i=1:length(tiempo) k11=f1(Zt,z1,z2); k12=f2(Zt,z1,z2); k21=f1(Zt+h/2,z1+k11*h/2,z2+k12*h/2); k22=f2(Zt+h/2,z1+k11*h/2,z2+k12*h/2); k31=f1(Zt+h/2,z1+k21*h/2,z2+k22*h/2); k32=f2(Zt+h/2,z1+k21*h/2,z2+k22*h/2); k41=f1(Zt+h,z1+k31*h,z2+k32*h); k42=f2(Zt+h,z1+k31*h,z2+k32*h); z1=z1+(k11+2*k21+2*k31+k41)*h/6; z2=z2+(k12+2*k22+2*k32+k42)*h/6; Zt=desplazamiento(i); disp([Zt,z1,z2]) X2(i)=z1; V2(i)=z2; end figure plot(tiempo,X2) title('Grafico Posición vs tiempo (sin amortiguacion)') xlabel('tiempo') ylabel('Posición') figure plot(tiempo,V2) title('Grafico Velocidad vs tiempo (sin amortiguacion)') xlabel('tiempo') ylabel('Velocidad') %espectro para factor de amortiguacion 0 (sin amortiguacion) tiempoesp=40:0.01:200; Fs = 1; % frecuencia T = 1/Fs; % periodo L = length(tiempoesp); % tiempo de la senal t = tiempoesp; %(0:L-1)*T; % vector tiempo % amplitudes x = X2(40:200); NFFT = 2^nextpow2(L); Y = fft(x,NFFT)/L; f = Fs/2*linspace(0,1,NFFT/2+1);

figure plot(f,2*abs(Y(1:NFFT/2+1))) title('Espectro de frecuencias (sin amortiguacion)') xlabel('Frecuencia (Hz)') ylabel('|Y(f)|')