Tag Info

New answers tagged

0

Try to evaluate the function at one point. You will see it does not take pure numerical values. There is still the symbol y. You need to set that too, of course. For example by Plot[(equation) /. y->5,{x,-10,10}]


1

The implementation you linked to works fine. I do not understand why you could not make it work. Verified it with Maple build-in function. Same result: LinearAlgebra[HouseholderMatrix](<1,2,3,4,5>); Mathematica: HouseholderMatrix[v_?VectorQ] := IdentityMatrix[Length[v]] - 2 Transpose[{v}].{v}/(v.v); HouseholderMatrix[{1, 2, 3, 4, 5}]; ...


9

As no one gave a FixedPoint answer, here is one: preparedStr = StringReplace[ "((your[drink {remember to}]) ovaltine)", { RegularExpression["[{[(]"] -> "{", RegularExpression["[)\]}]"] -> "}" }] "{{your{drink {remember to}}} ovaltine}" lst = {}; ...


33

In this response, I will focus upon the programming paradigm change when moving from Java to Mathematica. I will emphasize two differences between the languages. The first concerns the "feel" of writing Mathematica code. The second is about how iteration is expressed. The "Feel" of Mathematica Java is a reasonably conventional programming language, ...


4

str = "[can {and it(it (mix) up)} look silly]" paren = {{"\\(", "\\)"}, {"\\[", "\\]"}, {"{", "}"}}; allparen = StringJoin@Flatten[paren]; re = RegularExpression[ StringTake[ StringJoin[#[[1]] <> "[^" <> allparen <> "]*" <> #[[2]] <> "|" & /@paren] , {1, -2}]]; sr := Function[strl, Fold[ (Sow[" " ...


15

StringReplace method After reading other answers I was inspired to write a new method. I place it first because it is almost as concise as the method below yet it is more robust (and safe) because it preserves strings as strings. str = "[can {and it(it (mix) up)} look silly]"; StringReplace[str, {"["|"{"|"(" -> -1, "]"|"}"|")" -> 1, " " -> 0}] ...


10

This is a straightforward attempt at a recursive descent parser, favoring readability over brevity. First, the tokenizer: tokenize[str_] := DeleteCases[StringCases[str, { "(" -> open[1], "[" -> open[2], "{" -> open[3], ")" -> close[1], "]" -> close[2], "}" -> close[3], x : (Except[Characters["()[]{}"]] ..) ...


14

str = "[can {and it(it (mix) up)} look silly]"; i = 10; StringJoin @@ Last[Replace[Characters@str, {"[" | "(" | "{" :> Sow[" ", --i], "]" | ")" | "}" :> Sow["", ++i], c_ :> Sow[c, i]} , 1] ~Reap~ Range@10] (* " mix it up and it can look silly" *) This just scans through the characters one at a time and Sows them with an integer tag. ...


6

str = "[to {quite similar(answer (My) is)} Kuba's answer]"; mid = StringReplace[ StringReplace[ "Hold@" <> str, {"[" | "(" -> "{", "]" | ")" -> "}"}] // ToExpression // InputForm // ToString, "*" -> ","] // ToExpression // ReleaseHold {to, {quite, similar, {answer, {My}, is}}, Derivative[1][Kuba], s, answer} ...


5

This will give you an idea to start with I think: target = "[racket for {brackets (matching) is a} computers]" Rest@Reap[ Nest[With[{s = StringPosition[#, {"{", "(", "["}][[-1, 1]], e = StringPosition[#, {"}", ")", "]"}][[1, 1]]}, Sow[StringTake[#, {s + 1, e - 1}]]; StringDrop[#, {s, e}]] &, target, Length@StringPosition[target, ...


8

Reset the kernel first. str = "[can {and it(it (mix) up)} look silly]" new = StringReplace[ StringReplace[str, {"(" | "[" -> "{", ")" | "]" -> "}"}], {(a : WordCharacter ~~ " " | "" ~~ "{") :> a <> ",{", (a : WordCharacter ~~ " " ~~ b : WordCharacter) :> a <> "," <> b, ("}" ~~ " " | "" ~~ b : ...


3

The main thing that I am trying to show is that you can use Accumulate and that almost all these functions are compilable. I hope it also shows when to use Table rather than Do, to avoid making unnecessary ConstantArrays. I personally find the use of Table in your code confusing. Of course it is nice to localise variables from time to time, which is also ...


2

RandomChoice can take a list of weights, so you can do this: Join[RandomChoice[xelement -> elements, 24], PosFCC, 2]


0

elements = Transpose[{{Fe, Mn, Cu, Ni, Tc}}]; xelement = {0.3, 0.3, 0.15, 0.1, 0.15}; Introduce this: names = {Fe, Mn, Cu, Ni, Tc}; Evaluating names xelement then gives {0.3 Fe, 0.3 Mn, 0.15 Cu, 0.1 Ni, 0.15 Tc} and RandomSample[names xelement] gives {0.3 Mn, 0.15 Cu, 0.15 Tc, 0.1 Ni, 0.3 Fe} The last part of your question I cannot ...


4

Translate is probably the most efficient way to represent and display such a figure. With[{r = 30}, Graphics3D[{ Translate[Cuboid[], Union @@ (Permute[#, SymmetricGroup[3]] & /@ Coords[r]) ], {Green, Opacity[0.1], Sphere[{0, 0, 0}, r]} } ] ]



Top 50 recent answers are included