For Loops with Multiple Arrays
조회 수: 6 (최근 30일)
이전 댓글 표시
I'm not able to figure out how to create a for loop that has multiple arrays as inputs. The input data is:
m = [1:1:11]
r = [1:1:100]
z = [0:1:50]
H = 50
z1 = 10
The equation is:
p(r,z) =
sin((m*pi*z)/H)*sin((m*pi*z1)/H)*(1/(sqrt(r )))
I do not know how to set it up to get values of p(r,z) summed over the range of m. I also don't know how to get the values out of the loop so they can be used in other equations and plots. I've scoured the Answers board but I have not been able to construct any meaningful script yet - any and all insight is appreciated!
댓글 수: 2
James Tursa
2020년 12월 8일
You need to rethink this formula. Your starting r value is 0 and you are dividing by sqrt(r).
답변 (2개)
KALYAN ACHARJYA
2020년 12월 8일
r=1:1:100;
z=1:1:50;
H=50;
z1=10;
z=?? % Define z, I assumed it as a scalar (single value)
syms m
p=vpa(symsum(sin((m*pi*z)/H)*sin((m*pi*z1)/H)*(1./sqrt(r)),m,1,11))
Steven Lord
2020년 12월 8일
m = [1:1:11];
r = [1:1:100];
z = [0:1:50];
whos
The variable m is a 1-by-11 vector. The variable z is a 1-by-51 vector. What size would you expect sin(m*pi*z) to be?
- 1-by-11? If so how do you create 11 elements using z to perform the element-wise multiplication?
- 1-by-51? If so how do you create 51 elements using m to perform the element-wise multiplication?
- 11-by-51 or 51-by-11? These are actually possible using implicit expansion.
- Something else? If so what size and how would you create that using just m and z?
A11_51 = m.'.*z;
A51_11 = m.*z.';
whos A11_51 A51_11
FYI the sinpi function may be of use to you.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!