필터 지우기
필터 지우기

Storing values of a triple 'for loop'

조회 수: 2 (최근 30일)
Piotr Haciuk
Piotr Haciuk 2019년 3월 30일
댓글: dpb 2019년 3월 30일
Good morning all
I'm trying to simulate an Euler-Bernoulli's pinned pinned beam response, subjected to harmonic force located at point 'a'.
I wrote the script:
clc; clear all
%dimensions k.m.s
wi=10;L=100;th=0.5;I=(wi*th.^3)/12;A=wi*th;
%for steel
rho=2400; E=41e+9; EI=E*I;
F=2000*9.81; %[N]
wf=1; %force freq
tmax=1;
tmin=0.1;
a=50;%location of Force
w1=0;w2=0;w3=0;
hold all
for x=1:1:L
for t=tmin:tmax/10:tmax
for n=1:3
u=sin(n*pi*x/L); %n-th mode shape
ua=sin(n*pi*a/L); %mode shape near point a
F=F*sin(wf*t); %force magnitude
wn=(n*pi/L)^2*sqrt(EI/(rho*A)); %natural freq
w=((2/(rho*A*L))*(ua*u)/(wn^2-wf^2))*F; %lateral displacement
if n==1
w1=w1+w;
elseif n==2
w2=w2+w;
elseif n==3
w3=w3+w; %summation of w for each mode shape at each t and each x
end
end
end
end
hold off
What I want to achieve is to plot w (lateral displacement) with respect to x, and then with respect to t
The problem I have is how to sum up all the values of 'w', first for each 'n', and then for each 'x' ?
Let's say I'm dividing the length of the beam into 100 elements, so I'm expecting 100 summed up values of w?
  댓글 수: 1
dpb
dpb 2019년 3월 30일
See
doc meshgrid % example of 3D mesh
and rewrite your functions to be evaluated in vectorized form (use the "dot" operators) and then you can slice 'n dice the output however you wish.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Fluid Dynamics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by