my program not work

10 visualizaciones (últimos 30 días)
ebi
ebi el 19 de Oct. de 2013
Comentada: ebi el 20 de Oct. de 2013
hello my program not work , i want to form F and then according to formula, calculate fourier coefficient and fourier series of F and plot them . n=boundary of sigma, w1=is frequence .
clc
clear
L=input(' define L (lenght of wagon -m) : ');
V=input(' define V (speed of train -km/h) : ');
X1=input(' define X1(distance betwean 2 wagon -m) : ');
X2=input(' define X2(distance betwean 2 middle wheels -m): ');
X=input(' define X (distance betwean 2 near wheels -m) : ');
W=input(' define W (total weight of wagon and passenger -ton) : ');
disp( ' ' )
disp('Please wait 5 seconds only!');pause(1);
disp('Press any key to see All input.'); pause;
disp( ' ' )
V=V*1000/3600;disp([' *** V : (speed of train)= ',num2str(V),' m/s'])
disp([' *** L : (lenght of wagon) = ',num2str(L),' m'])
disp([' *** X1: (distance betwean 2 wagon) = ',num2str(X1),' m'])
disp([' *** X2: (distance betwean 2 middle wheels) = ',num2str(X2),' m'])
disp([' *** X : (distance betwean 2 near wheels) = ',num2str(X),' m'])
disp([' *** W : (total weight of wagon) = ',num2str(W),' ton'])
F1=W*9.81/8;
disp([' *** F1: (force of 1 wheel) = ',num2str(F1),' kN'])
t1=X/V;t2=(X+X2)/V;t3=(2*X+X2)/V;t4=(2*X+X2+(L-X2-2*X)+X1)/V;
disp([' *** F1 = ',num2str(F1),' kN'])
disp([' * t1 = ',num2str(t1),' s'])
disp([' * t2 = ',num2str(t2),' s'])
disp([' * t3 = ',num2str(t3),' s'])
disp([' * t4 = ',num2str(t4),' s'])
%t1 =0.0001*round(10000*t1);
%t2 =0.0001*round(10000*t2);
%t3 =0.0001*round(10000*t3);
%t4 =0.0001*round(10000*t4);
%F1 =0.0001*round(10000*F1);
s=input(' define s (number of sampeling > 500 ) : ');
t = 0:1/s:t4;
F = zeros(size(t));
F((t>=0&t<=t1)) = F1;
F((t>t1&t<t2)) = 0;
F((t>=t2&t<=t3)) = F1;
F((t>=t3&t<=t4)) = 0;
T=t4;
w1=2*pi/T;
a0=(1/T)*F*((t1-0)+(t3-t2)); % fourier coefficient
n=[0:1:input(' define n (sigma boundary) > 50 ) : ')];
an=2/T*F/(w1*n)*(sin(w1*n*t1)-0+sin(w1*n*t3)-sin(w1*n*t2)); % fourier coefficient
bn=2/T*F/(w1*n)*(-cos(w1*n*t1)+0-cos(w1*n*t3)+cos(w1*n*t2)); % fourier coefficient
subplot(4,1,1)
plot(t,F)
subplot(4,1,2)
plot(an),grid on
f=a0+an*cos(w1*n.*t/T)+bn*sin(w1*n.*t/T); %fourier Series
subplot(4,1,3)
plot(n,f),grid on
  1 comentario
Yannick
Yannick el 19 de Oct. de 2013
What exactly doesn't work in your program? What error or warning message do you get?

Iniciar sesión para comentar.

Respuestas (1)

Yannick
Yannick el 19 de Oct. de 2013
Editada: Yannick el 19 de Oct. de 2013
One problem is that you define n as a vector of values. When you then plug it into an and bn, it is trying to do matrix multiplications and "divisions" between vector -- something that is not possible in general (unless the sizes match up correctly), and anyway not what you want here (if you have 60 n values, it looks like you are expecting 60 an and 60 bn values).
So instead of * and /, you want to use the element-wise operators .* and ./. For more info: Array vs. Matrix Operations.
  2 comentarios
ebi
ebi el 20 de Oct. de 2013
i try to correct my mistake about sizes of matrix an , bn , f , t
and then plot fourier form of f . but i think my plot shape is not true
it must be like pictures that is attached.
my plot
true plot
t1=X/V;t2=(X+X2)/V;t3=(2*X+X2)/V;t4=(2*X+X2+(L-X2-2*X)+X1)/V;
disp([' *** F1 = ',num2str(F1),' kN'])
disp([' * t1 = ',num2str(t1),' s'])
disp([' * t2 = ',num2str(t2),' s'])
disp([' * t3 = ',num2str(t3),' s'])
disp([' * t4 = ',num2str(t4),' s'])
%t1 =0.0001*round(10000*t1);
%t2 =0.0001*round(10000*t2);
%t3 =0.0001*round(10000*t3);
%t4 =0.0001*round(10000*t4);
%F1 =0.0001*round(10000*F1);
t =[0:0.001:t4];
F = zeros(size(t));
F((t>=0&t<=t1)) = F1;
F((t>t1&t<t2)) = 0;
F((t>=t2&t<=t3)) = F1;
F((t>=t3&t<=t4)) = 0;
subplot(4,1,1)
plot(t,F),grid on
T=t4;
w1=2*pi/T;
a0=(1/T)*F1*((t1-0)+(t3-t2));
n=input(' define n (sigma boundary) > 350 ) : ');
an=[1:1:n];
bn=[1:1:n];
f=[1:1:n];
t=linspace(0,t4,n);
for i=1:n
an(1,i)=2/T*F1/(w1*i)*(sin(w1*i*t1)-0+sin(w1*i*t3)-sin(w1*i*t2));
bn(1,i)=2/T*F1/(w1*i)*(-cos(w1*i*t1)+0-cos(w1*i*t3)+cos(w1*i*t2));
f(1,i)=a0+an(1,i)*cos(w1*i*t(1,i)/T)+bn(1,i)*sin(w1*i*t(1,i)/T); %fourier serie
end
subplot(4,1,2)
plot(an),grid on
subplot(4,1,3)
plot(bn),grid on
subplot(4,1,4)
plot(f),grid on
ebi
ebi el 20 de Oct. de 2013
i just want to write a program to get the data from user and form formula of the piecewise force-time function and then plot it ,then plot fourier view of them and transform fourier and force spectrum .
please tell me the best way for define them.

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by