# Tag Info

## New answers tagged code-review

7

Bear in mind that I'm not completely sure what you are calculating, here is my 5 cents towards what can help you get a better performance. I haven't benched marked the MATLAB code on my system, but the changes implemented in Mathematica lead to a runtime decrease from 78.036 s down to to 0.171 s. The slowing factors where mainly that you handle a lot of ...

3

Regarding CountTrue: There is generally no need for the empty Module. You can use CompoundExpression if you need several operations in sequence. Here even that is not necessary. There is no need to count all appearances of True in an expression to determine if one is present: instead use MemberQ. That gives us: CountTrue[list_] := MemberQ[list, True] ...

2

The usual way to do this is to work with lists or arrays rather than try and create symbols. Here is a list version. chg = ConstantArray[Null, 5]; pos = ConstantArray[Null, 5]; Grid[{ Join[{"Chg"}, Table[With[{i = i}, InputField[Dynamic[chg[[i]]], FieldSize -> 4]], {i, Length[chg]}]], Join[{"Pos"}, Table[With[{i = i}, ...

2

This mess will get you something close to what you'd like, I'll explain the details below: symbols = {"a1", "a2", "a3"}; Grid[Prepend[Transpose@ Prepend[Map[{InputField[ToExpression["Dynamic[" <> # <> "$Chg]"],String,FieldSize->{4,1}], InputField[ToExpression["Dynamic[" <> # <> "$Pos]"], String,FieldSize -> {4, 1}]} ...

4

Proposal I recommend something like this: IRobot2[IStyle_String, ρ_, VaribleRange_List] := Block[{x, y, z}, With[{expr = Switch[IStyle, "xx", (y^2 + z^2), "yy", (x^2 + z^2), "zz", (x^2 + y^2), "xy", x y, "xz", x z, "yz", y z ]}, Integrate[ρ expr, ##] & @@ Join[{{z}, {y}, {x}}, ...

Top 50 recent answers are included