If statement for 2 different variables.
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have an equation:
x = [10 / pi + j / sin(i-1)] * cos[j * (i-1) * pi]
where i = 2 to 6 and j = 1 to 7. I am trying to make a code with both i and j. I am solving this equation for all combinations. For example, I want to solve the equation when i = 2 and j = 1, 2, ..., 7. And when i = 3, j = 1, 2, ..., 7. The end result should also be put in a matrix i by j = 5 by 7.
Thank you to all that reply!
3 comentarios
Respuestas (1)
Star Strider
el 22 de Sept. de 2023
Try this —
x = @(i,j) (10 / pi + j ./ sin(i-1)) .* cos(j .* (i-1) * pi);
i = 2:6;
j = 1:7;
[I,J] = ndgrid(i,j);
Iv = I(:);
Jv = J(:);
Xv = x(Iv,Jv);
X = x(I,J) % Matrix
figure
surf(I,J,X) % Surface Plot
grid on
colormap(turbo)
xlabel('i')
ylabel('j')
zlabel('x(i,j)')
ResultVectors = table(Iv,Jv,Xv) % Table Of Vectors
.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
