Using Nested Loops to calculate an equation
1 view (last 30 days)
Show older comments
Ti = [-20 0 15 33 52];
P = [30 60 75 100];
A = [2 1.5 1] *10^(-5);
Tf_all = zeros(1,length(Ti)*length(P)*length(A));
ii = 1; % counter
sigma = 5.6696*10^(-8);
for t = 1:length(ti)
for p = 1:length (P)
for a = 1:length(A)
Tf_all(ii) = nthroot((P/(sigma*A))+Ti,4)
ii = ii+1;
end
end
end
disp(Tf_all)
_________________________________________________________________________________________________________________________________________
This is the equation of a lightbulb filament. I was just wondering, how do you know the order of the nested loops, or does it not even matter?
1 Comment
darova
on 24 Apr 2019
You forgot indices:
Tf_all(ii) = nthroot((P(p)/(sigma*A(a)))+Ti(t),4);
I think the order doesn't matter in this case
Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!