Can someone check my for loop?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
I want to solve the following equation:

I made a double loop for calculation w(x,t) only for a particular point x=L/2. Since I'm getting disturbing solution I would like to firstly check if there is any problem with the code, and if not then move to changing constants/formula. I would kindly ask someone to check if the loops are correct aspecially for the sum? c,a as you can see are dependant on j. Vj is the part in big brackets in the formula. I'm firstly trying to sum all the Vj for different j, and then loop the formula for time t.
x=L/2;
for t=0:0.002:3
for j=1:100
oj= j*pi / L;
c= T/Dt * L/(j*pi)*(1- (-1)^j);
a = oj^4*(1+ (b*g*Y)/(oj^2*b + g));
k= n/Dt;
o1=sqrt(a/k);
A1= (c*o*sqrt(a/k)*k/a)/(k*o^2-a);
A2= c/(k*o^2-a);
Vj= A1*sin(o1*t) - A2*sin(o*t);
w=2/L*(Vj0+Vj*sin(j*pi*x/L));
Vj0=w;
end
plot(t,w,'o')
hold on
end
Answers (1)
Torsten
on 12 Jun 2017
x=L/2;
tvec=0:0.002:3;
for i=1:numel(tvec)
t=tvec(i);
w(i)=0.0;
for j=1:100
oj= j*pi / L;
c= T/Dt * L/(j*pi)*(1- (-1)^j);
a = oj^4*(1+ (b*g*Y)/(oj^2*b + g));
k= n/Dt;
o1=sqrt(a/k);
A1= (c*o*sqrt(a/k)*k/a)/(k*o^2-a);
A2= c/(k*o^2-a);
Vj= A1*sin(o1*t) - A2*sin(o*t);
w(i)=w(i)+Vj*sin(j*pi*x/L);
end
w(i)=2/L*w(i);
end
plot(t,w,'o')
hold on
Best wishes
Torsten.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!