How to call two sets of arrays in a nested loop?

2 visualizaciones (últimos 30 días)
Hirak
Hirak el 14 de Abr. de 2021
Editada: Hirak el 14 de Abr. de 2021
Hello Experts,
I have taken two sets of arrays. First one is 'alpha', which consists of 251 elements, the second one is 't', which consists of 721 data points.
For each alpha, I need to evaluate 'M', and thereby, (M*cos(t), M*sin(t)), which describes a 2 dimensional family of curves.
I need to create a dataset for 'M' considering each value of 'alpha' varying the values of 't' from 0 to 2*pi, and constructed the code expecting a matrix of [251*721] order. But the code returns only one value for M. There is no error message. Please help with your enlightened view.
Hirak
a=45;
x1=1:.02:6;
alpha=x1.^4;
t = 0:(pi/360):2*pi;
array=zeros(251,721);
for k1=1:.02:6
for k2=0:(pi/360):2*pi
M=a.*sqrt(cos(2.*k2)+sqrt(k1+(sin(2*k2).^2)));
x = M.*cos(k2);
y = M.*sin(k2);
end
end

Respuesta aceptada

VBBV
VBBV el 14 de Abr. de 2021
%if true
a=45;
x1=1:.02:6;
alpha=x1.^4;
t = 0:(pi/360):2*pi;
%rray=zeros(251,721);
p = 0:(pi/360):2*pi;
K = 1:0.02:6;
for k1= 1:length(K)
for k2=1:length(p)
M(k1,k2) =a*sqrt(cos(2*p(k2))+sqrt(K(k1)+(sin(2*p(k2).^2)));
x(k2) = M(k1,k2)*cos(p(k2));
y(k2) = M(k1,k2)*sin(p(k2));
end
end
Try this
  1 comentario
Hirak
Hirak el 14 de Abr. de 2021
Editada: Hirak el 14 de Abr. de 2021
Tried the code, but it appears k1 and k2 is not changing for x and y. I have just chnged it to
x(k1,k2) = M(k1,k2).*cos(p(k2));
y(k1,k2) = M(k1,k2).*sin(p(k2));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by