For Loops with Multiple Arrays
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
James Tursa
el 8 de Dic. de 2020
You need to rethink this formula. Your starting r value is 0 and you are dividing by sqrt(r).
Respuestas (2)
KALYAN ACHARJYA
el 8 de Dic. de 2020
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
el 8 de Dic. de 2020
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 comentarios
Ver también
Categorías
Más información sobre Performance and Memory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!