my program not work
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
el 19 de Oct. de 2013
What exactly doesn't work in your program? What error or warning message do you get?
Respuestas (1)
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
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!