Good morning,
I would like to ask you some help with writing a script. I have a beam with variable length. On this beam there are two types of load, whose values are 4 and 8. These two values alternate every 3 meters. I would like to write a script that for a number of times, starting from a fixed length, adding three meters for every loop, automatically it alternates the value of 4 and of 8.
For example starting from a beam of 12 meters, I have the loads which are 4, 8, 4 equidistant (3 meters from each other). I want to start a loop of 10 iteration, which adds 3 meter to the starting beam length (12 + 3) and add the load equal to 8 for the first iteration; for the second iteration it adds again 3 meters (12 + 3 + 3) and the added load is 4. These procedure should be performed n times.
Thanks a lot for your availability.

 채택된 답변

Paresh yeole
Paresh yeole 2020년 6월 4일

0 개 추천

% initialize n
length_of_beam = 12;
for i = 1 : n
length_of_beam = length_of_beam +3;
if mod(i,2) == 0
load(i) = 8;
else
load(i) = 4;
end
end

댓글 수: 5

Tommaso Donolato
Tommaso Donolato 2020년 6월 4일
I need as output the length of each iteration (so a vector 1 x n , where n are the n iteration and a matrix, where the rows correspond to the n iteration and the columns are the sum of the values of the loads ( first iteration = 4 8 4 (16), second iteration = 4 8 4 8 (24) and so on). In the end I have 2 vector 1 x n
Paresh yeole
Paresh yeole 2020년 6월 4일
편집: Paresh yeole 2020년 6월 4일
Looks like it is a homework assignment. Sorry I can't help you with that.
Tommaso Donolato
Tommaso Donolato 2020년 6월 4일
It's for my thesis. The last part of it needs this script.
% initialize n
length_of_beam(1) = 12;
load(1) = 4;
for i = 2 : n
length_of_beam(i) = length_of_beam(i-1) +3;
if mod(i,2) == 0
load(i) = load(i-1) + 8;
else
load(i) = load(i-1) + 4;
end
end
% you have two 1 * n vectors length_of_beam and load
Tommaso Donolato
Tommaso Donolato 2020년 6월 4일
Thank you very much, it works perfectly.

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

추가 답변 (1개)

Ora Nito
Ora Nito 2024년 6월 7일

0 개 추천

In vectorized form:
N = 10;% must be even
lob0 = 12;
dlob = 3;
length_of_beam_1 = lob0 - dlob + cumsum(dlob.*ones(1,N));
l1 = 4.*ones(1,fix(N/2));
l2 = 8.*ones(1,fix(N/2));
load_temp = [l1; l2];
load_1 = cumsum(load_temp(:))';

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

질문:

2020년 6월 4일

답변:

2024년 6월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by