Dear all I want to write a matrix that its arrays are dependent on i and j, could I write it without writing loops. my arrays are something like it a(i,j)=sin(2*pi*(i-1))/((sin(2*pi*(i-1))+sin(2*pi*(j-1))))). Thanks
MATLAB: Writing a matrix without loop
matrix+loop
Related Solutions
qini = zeros(1,6); % Initial guess
ci = fsolve(@funec,qini) % fsolve with the function handle, unknown variables and initial guess
% done many variations here, none of them worked
function ec = funec(x);q1 = x(1);q2 = x(2);q3 = x(3);q4 = x(4);q5 = x(5);q6 = x(6);ec =[... sin(q6)*(cos(q1)*cos(q2)*sin(q3)*sin(q4) - cos(q4)*sin(q1) + cos(q1)*cos(q3)*sin(q2)*sin(q4)) - cos(q6)*(cos(q2 + q3)*cos(q1)*sin(q5) + cos(q5)*sin(q1)*sin(q4) + cos(q1)*cos(q2)*cos(q4)*cos(q5)*sin(q3) + cos(q1)*cos(q3)*cos(q4)*cos(q5)*sin(q2)) - 3097002709122497/18014398509481984 cos(q6)*(cos(q1)*cos(q4) + cos(q2)*sin(q1)*sin(q3)*sin(q4) + cos(q3)*sin(q1)*sin(q2)*sin(q4)) + sin(q6)*(cos(q2 + q3)*sin(q1)*sin(q5) - cos(q1)*cos(q5)*sin(q4) + cos(q2)*cos(q4)*cos(q5)*sin(q1)*sin(q3) + cos(q3)*cos(q4)*cos(q5)*sin(q1)*sin(q2)) - 6124274932042799/36028797018963968 - sin(q2 + q3)*cos(q5) - cos(q2 + q3)*cos(q4)*sin(q5) - 139701203459709/140737488355328 70*cos(q1) + 360*cos(q1)*sin(q2) - 65*sin(q1)*sin(q4)*sin(q5) + 380*cos(q1)*cos(q2)*cos(q3) - 380*cos(q1)*sin(q2)*sin(q3) + 65*cos(q1)*cos(q2)*cos(q3)*cos(q5) - 65*cos(q1)*cos(q5)*sin(q2)*sin(q3) - 65*cos(q1)*cos(q2)*cos(q4)*sin(q3)*sin(q5) - 65*cos(q1)*cos(q3)*cos(q4)*sin(q2)*sin(q5) + 19869/50 sin(q6)*(cos(q1)*cos(q4) + cos(q2)*sin(q1)*sin(q3)*sin(q4) + cos(q3)*sin(q1)*sin(q2)*sin(q4)) - cos(q6)*(cos(q2 + q3)*sin(q1)*sin(q5) - cos(q1)*cos(q5)*sin(q4) + cos(q2)*cos(q4)*cos(q5)*sin(q1)*sin(q3) + cos(q3)*cos(q4)*cos(q5)*sin(q1)*sin(q2)) + 2202239090516653/2251799813685248 cos(q2 + q3)*cos(q6)*sin(q4) - sin(q6)*(sin(q2 + q3)*sin(q5) - cos(q2 + q3)*cos(q4)*cos(q5)) + 7591943296130745/288230376151711744 cos(q2 + q3)*cos(q1)*cos(q5) - sin(q5)*(sin(q1)*sin(q4) + cos(q1)*cos(q2)*cos(q4)*sin(q3) + cos(q1)*cos(q3)*cos(q4)*sin(q2)) - 102014544375725/18014398509481984 70*sin(q1) + 360*sin(q1)*sin(q2) - 380*sin(q1)*sin(q2)*sin(q3) + 380*cos(q2)*cos(q3)*sin(q1) + 65*cos(q1)*sin(q4)*sin(q5) + 65*cos(q2)*cos(q3)*cos(q5)*sin(q1) - 65*cos(q5)*sin(q1)*sin(q2)*sin(q3) - 65*cos(q2)*cos(q4)*sin(q1)*sin(q3)*sin(q5) - 65*cos(q3)*cos(q4)*sin(q1)*sin(q2)*sin(q5) - 1563/20 cos(q6)*(sin(q2 + q3)*sin(q5) - cos(q2 + q3)*cos(q4)*cos(q5)) + cos(q2 + q3)*sin(q4)*sin(q6) - 2129854249224409/18014398509481984 cos(q6)*(cos(q1)*cos(q2)*sin(q3)*sin(q4) - cos(q4)*sin(q1) + cos(q1)*cos(q3)*sin(q2)*sin(q4)) + sin(q6)*(cos(q2 + q3)*cos(q1)*sin(q5) + cos(q5)*sin(q1)*sin(q4) + cos(q1)*cos(q2)*cos(q4)*cos(q5)*sin(q3) + cos(q1)*cos(q3)*cos(q4)*cos(q5)*sin(q2)) - 8872946535830847/9007199254740992 cos(q2 + q3)*cos(q5)*sin(q1) - sin(q5)*(cos(q2)*cos(q4)*sin(q1)*sin(q3) - cos(q1)*sin(q4) + cos(q3)*cos(q4)*sin(q1)*sin(q2)) - 8718732974408059/72057594037927936 360*cos(q2) - 380*cos(q2)*sin(q3) - 380*cos(q3)*sin(q2) - 65*cos(q2)*cos(q5)*sin(q3) - 65*cos(q3)*cos(q5)*sin(q2) - 65*cos(q2)*cos(q3)*cos(q4)*sin(q5) + 65*cos(q4)*sin(q2)*sin(q3)*sin(q5) - 39571/100];end
You could try the following.
J=5;while J<13 if J>=7 j=1:6; else j=1:J; end z=63*pi.*(J-j); %piecewise multiplication
disp(z) J=J+1;end
This satisfies the conditions of j less than or equal to J and j less than 7.
When j is not changing in size, i.e. after the first two iterations of the loop, you could in fact get a solution therein without any loops:
j=1:6;J=[7:13]';z=63*pi.*(J-j)
Best Answer