2
저는 Mathematica 프로그래밍의 초보자이며 도움이 필요합니다. 임의의 배열 요소를 가져 오는 함수를 작성하려고 노력 중이며 수학 LibreOffice에서 사용하도록 특별히 형식이 지정된 문자열을 작성합니다.배열 (Mathematica)에서 문자열을 만드는 함수
OOForm[MM_] :=
(strMM = "left (matrix{";
For[i = 1, i < Dimensions[MM][[1]], i++] { (* not last row *)
For[j = 1, j < Dimensions[MM][[2]], j++] { (* not last element from the row *)
strMM = strMM <> ToString[MM[[i, j]], InputForm] <> "#";
}; (* last element from the row *)
strMM = strMM <> ToString[MM[[i, Dimensions[MM][[2]]]], InputForm] <> "##";
};
For[j = 1, j < Dimensions[MM][[2]], j++] { (* last row without the last element *)
strMM = strMM <> ToString[MM[[Dimensions[MM][[1]], j]], InputForm] <> "#";
}; (* last element *)
strMM = strMM <> ToString[MM[[(Dimensions[MM][[1]]), Dimensions[MM][[2]]]], InputForm] <> "} right)";
strMM;
)
같은 입력을 : 다음
내 코드는
"left (matrix{3/2#-1#-2#-2#-2##0#3#6#10#14##-6#3/2#5#5#5##19/2#-7#-35/2#-24#-61/2} right)"
그러나이 출력 발생 :
A = {{3/2, -1, -2, -2, -2}, {0, 3, 6, 10, 14}, {-6, 3/2, 5, 5, 5}, {19/2, -7, -35/2, -24, -61/2}};
예상 출력 것은
을"left (matrix{-61/2#-61/2##-61/2#-61/2} right)"
예상되는 출력이 아니지만 오류를 찾을 수 없습니다.
감사합니다.
답장을 보내 주셔서 감사합니다. 그리고 여러분 말이 옳습니다. 저는 C 스타일 프로그래밍을 Mathematica에 이식하려고했습니다. :) –