multi-variable looping problem

조회 수: 1 (최근 30일)
Arjun
Arjun 2014년 5월 7일
댓글: Arjun 2014년 5월 8일
I need to perform a multi-variable loop for the following conditions and I have problem doing it
Info: initial_a = 1000 initial_b = 100 initial_c = 0.2 initial_d = 10
Equation x = 5a + b^2 + c/2 + 0.25d
program should start with initial_a does not changes but value of b changes with increment of 10 till 200, a changes with increment of 0.01 till 0.3 and d changes with increment of 1 till 20.
then in continues to by increasing value of initial_a by 100 and the same condition of b,c,d applies
the loop should end when intial_a is 20000
  댓글 수: 2
José-Luis
José-Luis 2014년 5월 7일
편집: José-Luis 2014년 5월 7일
What have you tried so far? Sounds like your problem could be solved with four nested loops. It could also be achieved through vectorization. What's your increment step?
Arjun
Arjun 2014년 5월 8일
I tried the nested loops, it kinda worked....but what do u mean by vectorization? tq

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

채택된 답변

Hugo
Hugo 2014년 5월 7일
for a=1000:100:20000
ia=floor(a/100)-9;
for b=100:10:200
ib=floor(b/10)-9;
for c=.2:.01:.3
ic=floor(c/.01)-19;
for d=10:1:20
id=d-9;
x(ia,ib,ic,id)= 5*a + b^2 + c/2 + 0.25*d
end
end
end
end
The variables ia, ib, ic, id are there just for being able to index the variable x. It would also be advisable to allocate space for x before the loops using x=zeros(191,11,11,11);

추가 답변 (1개)

Arjun
Arjun 2014년 5월 7일
tq very much my fren =)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by