Tag Info

New answers tagged

1

Maybe something like this? myfun[j_] := Block[{ans = Range[j]}, ToExpression["phi" <> ToString[j] <> " = " <> ToString@Total[ans]] ]; myfun[10]; phi10 55


1

I believe this accomplishes your goal: Table[ContourPlot[ Norm[{x, y}, p] == 1, {x, -1.2, 1.2}, {y, -1.2, 1.2}, PerformanceGoal -> "Accuracy", ImageSize -> 250, PlotLabel -> Row[{TraditionalForm[HoldForm[p]], "\[ThinSpace]=", p}]], {p, {1, 2, 3, 4, 10, 50, 500}}] The \[ThinSpace] is included just to properly space before the equal ...


5

Since we can not see the source code of Mathematica, we don't know the detailed algorithm Mathematica use to do string pattern searching. But in most other languages, they use KMP algorithm to do explicit string matching. KMP is in fact a very compact design of the DFA pattern matching algorithm. You can find a comparison here. You can see that the ...


0

You can use StringSplit and RegularExpression to do this: In[3]:= StringSplit[test, RegularExpression[""]] Out[3]:= {"k", "s", "p", "e"} In[4]:= Head[First[%]] Out[4]:= String


0

lst = "kspe"; lst = ToExpression@Characters[lst] First[lst] Last[lst]


0

Insert the passage you want shifting as a string: str = HELLO WORLD Then, define this function: f[x_] := If[64 < x < 91, (Mod[x - 65 + s, 26] + 65), x] Where s is your shift (positive or negative). Then, simply map the function over the character codes of your string: FromCharacterCode[Map[f, ToCharacterCode[str]]] This will result in a ...


1

Using insights from WReach and Aisamu here's a version with good properties on system names: humpCharacters = Flatten@{CharacterRange["A", "Z"], CharacterRange["0", "9"]}; . StringSplit[systemNames, c : humpCharacters ~~ rest : Except[Append[humpCharacters, "$"]] .. :> c <> rest] // // Map[Select[# != "" &]] From visual ...


9

Here is a method using StringSplit and RegularExpression: StringSplit[systemNames, RegularExpression["(?=[$[:upper:]])"]] (* {{A,A,S,Triangle},{Abelian,Group},{Abort},{Abort,Kernels},{Abort,Protect}, {Above},{Abs},<<5192>>,{$,User,Documents,Directory},{$,User,Name},{$,Version}, {$,Version,Number},{$,Wolfram,I,D},{$,Wolfram,U,U,I,D}} ...


8

You can do all of it directly with StringCases! StringCases[systemNames, hump : (CharacterRange["A", "Z"] | DigitCharacter) | "$" ~~ restOfCamel : CharacterRange["a", "z"] ...] (* {{A,A,S,Triangle},{Abelian,Group},{Abort},{Abort,Kernels},{Abort,Protect}, {Above},{Abs}, ...5182... ,{$,User,Base,Directory}, ...


5

The rules seem to be amenable to a recursive regular expression: extract[s_] := StringCases[s, RegularExpression["b|c|(a(?R)*d)"]] extract["abdcbaacdabbdd"] (* {"abd", "c", "b", "aacdabbdd"} *) Further examples: extract["b"] (* {"b"} *) extract["bcbbc"] (* {"b", "c", "b", "b", "c"} *) extract["ad"] ...


4

I was able to match your example, but I'm not sure I completely grasped the problem! exampleStr = "abdcbaacdabbdd" checkSubStr[str_String] := And @@ ((Count[Take[Characters@str, #], "a"] >= Count[Take[Characters@str, #], "d"]) & /@ Range[StringLength@str]) StringCases[exampleStr, Shortest@ tot : ("b" | "c" | (x : ("a" ~~ ___ ~~ "d")) /; ...


2

Not anyhere elegant as the OP's own method, but ... staying in the String universe may be a good alternative. Stealing @Aisamu's string pattern and using only String functions: ClearAll[cssF, strngCF]; cssF = Function[{s}, And @@ Flatten[{Equal @@ (StringCount[s, #] & /@ {"a", "d"}), (StringCount[#, "a"] >= StringCount[#, "d"] ...


11

Not much to say here other than this is a nasty bug, but since you seemed to be curious what exactly goes wrong, here's the function that does the formatting: This function breaks the number into integer and fractional parts, converts both to a string (as integers) and joins them with a decimal point. The integer part of -0.5 is 0 which is formatted as ...


1

Thank you for a well-written question with complete code that made this reasonable to answer. Welcome to Mathematica Stack Exchange. :-) You do not need UpValues definitions here. That would only apply if you were attempting to add a rule to e.g. Plus rather than Sup, yet your use of TagSetDelayed makes it clear that you are attaching the rule to Sup. ...


9

QuantityMagnitude[WolframAlpha[#, {{"Result", 1}, "ComputableData"}]] & /@ {"Apple company revenue", "Apple company interest expense", "Apple company employees"} (* {1.828*10^11, 3.84*10^8, 97000} *) Update: Exchange rate conversion WolframAlpha[#, {{"Result", 1}, "ComputableData"}] & /@ {"Sony company revenue", "Sony company interest ...


1

There's special function for generating fortran-like forms: SetOptions[$Output, PageWidth -> 100] FortranForm[string] And certainly you can manage string manually. To insert new strings in the string you can write something like this: string = StringJoin[ToString /@ Range[1000]]; step = 10 StringInsert[string, "&&\n&&", Range[step, ...


0

This works for me with large data (1E6 points) in Ver 8.0.1: test = Import["scope_29_1.csv", "Data"]; test2 = ToExpression[Drop[test, 2]]; "Data" forces mathematica to convert 1.734E-003 into 0.001734 but keeps as string because the first 2 lines contains names. "Drop" Keeps the first non-numerical lines out.


3

Regular expressions are cryptic, but they offer look-ahead and look-behind capabilities that are unavailable to regular string patterns: split[s_] := StringSplit[s, RegularExpression["( |,|(?<![[:alpha:]])[-.]|[-.](?![[:alpha:]]))+"]] split[",,temp sp.a tiral - dump NV-A rambo.6833. 16,rgcht"] (* {"temp", "sp.a", "tiral", "dump", "NV-A", "rambo", ...


1

Import["binary.txt"] in this case is equivalent to Import["binary.txt", "Text"] not to Import["binary.txt", "String"] Documentation states that Import["binary.txt"] "reads a text file, taking the character encoding to be "UTF8" by default." Whereas for format "String" documentation states that "imports a raw sequence of bytes and returns them as a ...


1

trialtext = ",,temp sp.a tiral - dump NV-A rambo.6833. 16,rgcht"; StringTrim@StringSplit[trialtext, {"," | "-" | ".", x : PatternSequence[Except[WhitespaceCharacter] .. ~~ "." | "-" ~~LetterCharacter ..] :> x}] (* {"temp", "sp.a", "tiral", "dump", "NV-A", "rambo", "6833", "16", "rgcht"} *)


3

Introduction There are a few ways to make such a table: (1) a symbolic way that seems conceptually clear and whose slowness is not prohibitive for a table of at most a few thousand entries; (2) using the table created by NDSolve in solving the equation by integrating its derivative either (a) directly or (b) correcting the errors in it; and (3) making a ...


2

I'll try to address this one step at a time. Since a is assigned a value of 0.022 I shall assume we will be working numerically. Let's plot our function. a = 0.022; expr = (1/2) x Sqrt[1 + 4 a^2 x^2] + ArcSinh[2 a x]/(4 a) Plot[expr, {x, -1*^5, 1*^5}] 1/2 x Sqrt[1 + 0.001936 x^2] + 11.3636 ArcSinh[0.044 x] There appear to be no complications so ...



Top 50 recent answers are included