Filter löschen
Filter löschen

Storing values of a triple 'for loop'

2 Ansichten (letzte 30 Tage)
Piotr Haciuk
Piotr Haciuk am 30 Mär. 2019
Kommentiert: dpb am 30 Mär. 2019
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 Kommentar
dpb
dpb am 30 Mär. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Fluid Dynamics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by