Need some help with loop

조회 수: 1 (최근 30일)
Jama Ali
Jama Ali 2021년 5월 20일
댓글: Chad Greene 2021년 5월 20일
Hi, I need some help with creating a loop so every number of v is evaluated with every p in the LoF formula. Meaning 50*5^2*FVF/FV for the first v-value and 50*10^2*FVF/FV for the second v-value, and when it is done with p= 50, starting over with p=100 and evaluating all the v-values with respect to that p and so one.
I appricate the help.
  댓글 수: 3
Jama Ali
Jama Ali 2021년 5월 20일
No, I am not required to use a loop. Just thought it was the only way :(
Tayyab Khalil
Tayyab Khalil 2021년 5월 20일
First thing, rather than posting pics of your code it would be better if you copy pasted the actual code.
what you are looking for is a nested for loop. Here is the code:
v = [5:5:40];
p = [50:50:300];
FVF = 0.001;
Fv = 27056;
LOF = zeros(length(p), length(v));
for i = 1:length(p)
for j = 1:length(v)
LOF(i, j) = p(i) * v(j)^2 *FVF/Fv;
end
end
I stored the values in LOF in form of a matrix, where each row coreesponds to the values obtained by the corresponding entry in p.

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

답변 (1개)

David Hill
David Hill 2021년 5월 20일
No loop needed.
[v,p]=meshgrid(5:5:40,50:50:300);
FVF=.001;
Fv=27056;
LoF=p.*(v.^2)*FVF*Fv;
  댓글 수: 2
Tayyab Khalil
Tayyab Khalil 2021년 5월 20일
EDIT: Division by Fv needed in LoF equation
Chad Greene
Chad Greene 2021년 5월 20일
@David Hill The point of homework isn't to get the answer...The point is to learn. So if you're going to give someone the answers to their homework, at least put in some effort to teach them why you're doing each step.

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

카테고리

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