Skip to main content

Posts

Showing posts from November, 2014

string manipulation - Dataset breaks multi-character StringSplit

Given ds = Dataset[{"a b", "c-d"} ] multi-character StringSplit is broken with Dataset (10.1 regression?) ds[All, StringSplit[#, {" ", "-"}] &] though single split charaters works: ds[All, StringSplit[#, " "] &] // Normal {{"a", "b"}, {"c-d"}} As does plain non-Dataset version of multi-char of course (same output as above) ds // Normal // Map[StringSplit[#, {" ", "-"}] &] Answer This issue is due to the same type-inferencing problem described here . Using printSignatures from the referenced answer, we can see that the type inferencer will only accept a single string as the second argument, not a list: printSignatures[StringSplit] (* {Vector[Atom[String], n_]} {Atom[String]} {Atom[String], Atom[String]} {Vector[Atom[String], n_], Atom[String]} *) This list of valid signatures will only accept a single string as the second argument. The referenced an

packages - FeynArts not working properly

So I have installed all FeynArts folders (from 3.5 to 3.7) with FeynCalc 8.0.1., and none of it is working properly :\ First I load the path to specific FeynArts package (3.5 for instance), then, by: << HighEnergyPhysics`FeynCalc`; I load FeynCalc, and he says Loading FeynCalc from C:\Users\*****\AppData\Roaming\Mathematica\Applications\HighEnergyPhysics FeynCalc 8.1.0 For help, type ?FeynCalc, open FeynCalcRef8.nb or visit www.feyncalc.org Loading FeynArts, see www.feynarts.de for documentation FeynArts 3.5 patched for use with FeynCalc So everything seems nice, right? Wrong! I even load FeynArts package, and no errors. But when I want to initialize the proper model I get: In[9]:= InitializeModel[SM] During evaluation of In[9]:= During evaluation of In[9]:= loading generic model file C:\Users\*****\AppData\Roaming\Mathematica\Applications\HighEnergyPhysics\FeynArts-3.5\Models\Lorentz.gen During evaluation of In[9]:= TagSetDelayed::tagnf: Tag FourVector not found in \! \(Traditio

Change variables in differential expressions

I have a fairly complicated differential expression in terms of a variable r and two unknown functions of r, B[r] and n[r]. I want to do a Taylor expansion of this around r=infinity. I want to do this by defining a new variable x=1/r and changing from r to x within my expression, then expanding around x=0. Say the expression looks (more or less) like n[r] (3 r B'[r]^2 - 4 B[r] (2 B'[r] + r B''[r])) How do I turn this from something in terms of {r, n[r], B[r]} to something in terms of {x, n[x], B[x]}? I'm not sure how to get Mathematica to work through the chain rule and change the dependent variable in the derivatives, and I also frequently get errors along the lines of "1/r is not a valid variable." EDIT I've managed to find at least a solution, although I'd imagine Mathematica has far more elegant ways of doing this. Hopefully if there's a cleaner way to do this someone will post it anyway. It would also be nice to have a more general method

string manipulation - How do I construct a "named character" programmatically?

Why am I getting the error Syntax::sntunc: Unicode longname in the string is unterminated. from the following? astroSymbol[name_String] := ToString[ToExpression["\[" <> name <> "]"]] <> "" ; Is there something I need to do to wrap the escape sequence to avoid this error? Answer To include a backslash in a string, you need to escape it, like so: "\\[" <> name <> "]"

performance tuning - Fast function to do multiple rectangle region checks

Suppose I have a set of "rectangles" and a set of "points": SeedRandom[5] rects = RandomReal[10, {5, 2, 2}] pts = RandomReal[10, {5, 2}] {{{0.00790584, 0.650192}, {9.89555, 9.68768}}, {{2.00866, 8.19521}, {0.897634, 9.70701}}, {{2.2991, 6.12503}, {0.96816, 5.48855}}, {{1.32548, 2.32332}, {7.76135, 5.50949}}, {{0.586896, 9.60602}, {0.982487, 0.343521}}} {{8.06562, 4.39186}, {1.42284, 0.27687}, {0.794711, 8.59505}, {2.42136, 8.42835}, {5.54556, 7.21645}} I want to find out which points are members of their associated rectangles. One slow possibility is to use RegionMember : MapThread[RegionMember[Rectangle@@#1, #2]&, {rects, pts}] {True, RegionMember[ Rectangle[{2.00866, 8.19521}, {0.897634, 9.70701}], {1.42284, 0.27687}], RegionMember[ Rectangle[{2.2991, 6.12503}, {0.96816, 5.48855}], {0.794711, 8.59505}], False, RegionMember[ Rectangle[{0.586896, 9.60602}, {0.982487, 0.343521}], {5.54556, 7.21645}]} This approach doesn't work because RegionMember needs the

recursion - Compile recursive function modifying global variables

How to compile recursive formula when it relies on more than a few global variables (global to the topmost compiled function)? It is unreasonable to pass on all such variables to each recursive subroutine (there are more than one), as: that would require a lot of tensor copying which would cause a slowdown; even if passing globals would be possible, returning all affected globals from each subroutine would be tedious as each function must return a regular tensor of uniform data type. Consider the following toy problem to calculate the factorial: fact[x_] := Module[{sub, global = 1}, sub[y_] := If[y > 0, global = global*y; sub[y - 1]]; sub@x; global]; How to compile it without passing global to sub ? While this code works nicely in the general Mathematica interface, the following compiled version will call MainEvaluate as there is a SetDelayed expression which the compiler cannot handle: factC = Compile[{{x, _Integer}}, Module[{global = 1, sub}, sub[y_] := If[y >

front end - What is the complete list of valid FrontEnd Packet types?

In response to my question How can I get the unchanged Box form of an arbitrary expression? John Fultz answered with a method using the hilariously named FrontEnd`UndocumentedTestFEParserPacket . What is the complete list of such Packets? Related: Answer Once again thanks to John Fultz we know a command that returns the complete list of these packets: MathLink`CallFrontEnd[FrontEnd`NeedCurrentFrontEndSymbolsPacket[]][[1, 1, 4]] Results from Mathematica 7: "" "Null" "CompoundExpression" "List" "Execute" "FrontEndExecute" "KernelExecute" "OpenParallelLinksPacket" "KernelStartupCompleted" "ReassignInputNamePacket" "InputNamePacket" "OutputNamePacket" "ReturnTextPacket" "ReturnInputFormPacket" "ReturnPacket" "TextPacket" "DisplayPacket" "DisplayEndPacket" "SyntaxPacket" "InputPacket" &quo

graphics - Creating ghost trail effects

Does anyone know how to create a ghost trail effect? For a simple example look at this screenshot: You can find the actual animation here . What I would ultimately like to see it happen is to make the object move based on whatever equations you specify it. For instance, to make it move around a circle the object should have the position (cos[t], sin[t]) . Or, lets say you have a list of specified coordinates {(x1,y1), (x2,y2), ..., (xn,yn)} , All I want to be able to see is the trace as an object takes in the coordinates I specify. Here is a simple ball moving without the ghosting effect. Animate[ Graphics[ Disk[{Cos[u], Sin[u]}, .25], PlotRange -> {{-2, 2}, {-2, 2}}, ImageSize -> 400, Axes -> True ], {u, 0, 6} ] Answer Here is a simple approach to create a ghost trail: obj[{xfunc_, yfunc_}, rad_, lag_, npts_][x_] := MapThread[ {Opacity[#1, ColorData["SunsetColors", #1]], Disk[{xfunc@#2, yfunc@#2}, rad Exp[#1 - 1]]} &, Through[{Rescale, Identity}

Differentiation inside package

I am trying to put all my functions in a single package and some of them do not work because of differentiation. Suppose I have the following package BeginPackage["Diff`"] Diff[yy_]:=Module[{cc},cc=D[yy,x[1]];cc]; End[] EndPackage[] And suppose I do the following < Diff[x[1]^2] I expect to get 2x[1], but I get 0, what is going on? Probably I am missing something very simple. And yes I need variables in the form x[1],x[2],..., not x,y,z. Interestingly everything works perfectly fine if I do it without packaging: Diff[yy_]:=Module[{cc},cc=D[yy,x[1]];cc]; Diff[x[1]^2] The last operation gives 2x[1]. Answer If you define Diff in a private context, like BeginPackage["Diff`"] Diff::usage = "" Begin["`Private`"] Diff[yy_] := Module[{cc}, cc = D[yy, x[1]]; cc]; End[] EndPackage[] then you will get << Diff` Diff[x[1]^2] (* 0 *) That's because the x referred to in the package is in the Diff`Private` context: Definition@Diff // InputForm (

guidelines - Package organization

When writing a Mathematica package Foo, with functions f1, f2 and f3, one can use the template: BeginPackage["Foo`"]; f1::usage = "f1[] ...."; f2::usage = "f2[] ...."; Begin["`Private`"]; f1[]:= code for f1 f2[]:= code for f2 f3[]:= code for f3 (not visible as only in the private context) End[]; EndPackage[]; What I do not like is when your package is growing, there can be a long "distance" (not fitting in your text editor) between "f1::usage" and the actual f1 code. This is error prone concerning coherence between doc and code. So I would like to group common stuff together. My question is: Is it possible and is it a good practice (without side effect) to group things like below? BeginPackage["Foo`"]; Begin["`Private`"]; Foo`f1::usage = "f1[] ...."; Foo`f1[]:= code for f1 ... Foo`f2::usage = "f2[] ...."; Foo`f2[]:= code for f2 ... f3[]:= code for f3 (private as before) End[] EndPackage[

mesh - Writing loops for triangle elements

I'm kind of new to using Mathematica, so any help is great. I'm trying to write a program that will create a list or matrix that will give each small triangle's point numbers. For example if given an isosceles right triangle, the example below gives the sides as 4 and the numbering of the points is just like below, then it should give a list or table such as dat= {{1,2,6},{2,3,7},{3,4,8},{4,5,9},{6,7,10},{7,8,11},{8,9,12},{10,11,13}, {11,12,14},{13,14,15},{2,6,7},{3,7,8},{4,8,9},{7,10,11},{8,11,12},{11,13,14}}. I've tried writing a few loops, but am not getting anywhere. I know that the starting number on the diagonal of the big triangle will add whatever the side is and start decreasing that value as u go up. For example, the first point always starts at 1, and as u move up the rows of triangle, you add 1+(x+1) to get 6. Then going up the next row of triangles, it is 6+(x) , to get 10. And so on. So I see two iterators? once increasing? one decreasing? Any help or

plotting - Smoothing a cusp in plotted data

Here are my data points: 59.51 -59.3642 58.9944 -58.8079 58.4836 -58.2471 57.9778 -57.6819 57.4769 -57.1122 56.981 -56.5383 56.4901 -55.96 56.0043 -55.3775 55.5236 -54.7907 55.048 -54.1998 54.5777 -53.6048 54.1125 -53.0056 53.6525 -52.4025 53.1979 -51.7953 52.7486 -51.1842 52.3046 -50.5692 51.866 -49.9503 51.4328 -49.3277 51.0051 -48.7013 50.5828 -48.0712 50.4206 -47.8259 50.0013 -48.2641 49.5782 -48.6986 49.1514 -49.1294 48.7208 -49.5564 48.2865 -49.9797 47.8485 -50.3992 47.4069 -50.8148 46.9616 -51.2266 46.5128 -51.6344 46.0604 -52.0384 45.6046 -52.4383 45.1452 -52.8343 44.6824 -53.2263 44.2163 -53.6141 43.7467 -53.998 43.2738 -54.3777 42.7977 -54.7532 42.3182 -55.1246 41.8356 -55.4918 41.3497 -55.8548 40.8607 -56.2135 40.3686 -56.5679 39.8734 -56.918 39.3752 -57.2638 38.874 -57.6053 38.3698 -57.9423 37.8627 -58.2749 37.3528 -58.6031 36.8399 -58.9269 36.3243 -59.2461 35.8059 -59.5608 35.2848 -59.871 34.761 -60.1767 34.2345 -60.4777 33.7055 -60.7741 33.1738 -61.066 32.6397 -61.3531 32

graphics - Image with grid lines

I have an image of a certain size. img = Image[source, ImageSize -> escala]; I want to add a grid with a scale (0 to maxX from left to right and 0 to maxY from top to bottom). The problem is that GridLines is an option for Graphics , not for Image . How can I overlay grid lines on my image? Answer img = ExampleData[{"TestImage", "Lena"}]; grid = Graphics[{}, GridLines -> Automatic, PlotRangePadding -> None, GridLinesStyle -> Directive[Red, Thick], ImageSize -> ImageDimensions@img]; Overlay[{img, grid}] For arbitrary numbers n+1 and m+1 of equidistant gridlines with automatic dependence on the ImageDimensions of img (which does not have to be a square either): n = 13; m = 7; sub1 = Subdivide[-1, 1, n]; sub2 = Subdivide[-1, 1, m]; grid = Graphics[{}, GridLines -> {sub1, sub2}, PlotRangePadding -> None, GridLinesStyle -> Directive[Red, Thick], ImageSize -> ImageDimensions@img]; Overlay[{img, grid}]

front end - Evaluate selection in new window or new notebook?

Sometimes when you have long code you need to check some part of this code. the way I am using currently is to selected the part that I want and then copy it to new notebook and then evaluate it there. this process becomes annoying when repeated several times. is there a better way to automatically evaluate selection in new notebook without need to go through copy paste procedure? Update : Thanks to halirutan for his suggestions. But one of my concerns is to evaluate selection within the cell in to another window. For example: how to evaluate the selection without manually copy and paste. If the cell itself contain long content, then the only way to debug the cell is be copying part by part and pasting into another notebook and evaluate as a whole new cell.

import - Why does Mathematica consume so much memory when reading binary data?

There are somewhat similar questions on here, but I didn't find a satisfying answer for this case: I import a 1.7 GB binary data file using the following command: BinaryReadList["/path/to/file", "Real64"] It runs fine but the memory usage peaks at 18 GB during the import process, which is about 10 times the file size. Is there a more efficient way to do this? Why does Mathematica consume that much memory? edit: It turned out, that almost all the memory is consumed by displaying the output. When I add a semicolon after the command, the consumed memory is close to the file size. This might not be a bug, but I still wonder why Mathematica behaves like this. here is a test case: generate a file with: BinaryWrite["test.dat", ConstantArray[99, 1*^8], "Integer8"]; quit the kernel to reset MaxMemoryUsed[] and execute the following: membefore = MemoryInUse[]; BinaryReadList["test.dat", "Real64"] (MaxMemoryUsed[] - membefore)/(UnitC

pattern matching - MatchQ’ing Except[…] and Except[…]

A PostScriptForm 1 for Mathematica must recurse over the likes of Plus[…] . Output should be as follows: 9+n: either 9 n add or n 9 add 9-n: 9 n sub -9+n: n 9 sub -9-n: -9 n sub So for my purposes first step is to find the first item of a list that is neither Times[-1, _] nor (n_Integer /; n < 0) . But Position[(9 + n), (Except[Times[-1, _]] && Except[(n_Integer /; n < 0)]), 1, Heads -> False] returns a grumble: “Except::named: "Named pattern variables are not allowed in the first argument of Except[n_Integer/;n<0]”. Please, kind experts of Mathematica.StackExchange.com, how could this most naturally be done? This problem has raised other issues — likely to be my failure to master Mathematica’s object model. thing = 9 (* Easy peasy *) MatchQ[thing, (Except[Times[-1, _]])] (* returns True: happiness *) MatchQ[thing, (Except[_?Negative])] (* also returns True: happiness *) MatchQ[thing, (Except[Times[-1, _]] && Except[_?Negative])] (* returns False in

probability or statistics - Log-log scale smooth histogram

How can I create a smooth histogram with a log-log scale? I can use Histogram[data, "Log", "LogCount"] to get a log-log histogram, or I can use SmoothHistogram[data] to get a smooth histogram, but is there a way to combine these two functionalities? Answer You can simply get the SmoothKernelDistribution and build the plot as you'd like: data = Table[Sin[x]^3 + 1, {x, 0, 6 Pi, 0.1}]; dist = SmoothKernelDistribution[data]; LogLogPlot[PDF[dist, x], {x, 0.01, 2}]

Counting the number of instances of one sub-string within a given string within a lower- and upper-bound gap of a second sub-string

Please consider the situation where I give you a list where entries are drawn from a fixed set of characters: alphabet = {0,1,2}; numElements = 10^3; bigString = StringJoin[Map[ToString, RandomChoice[alphabet, numElements]]]; I provide you two strings: string1 and string2 . I'd like to count the number of instances where string2 occurs within a lower-bound and upper-bound "distance" of string1 , and by "distance" I mean this in terms of the count for the number of characters in the gap region between string1 and string2 (i.e. the number of characters counting from immediately after the last character in string1 and the immediately before the first character in string2 if string1 occurs before string2 , and vice versa if string2 occurs before string1 ). There may be multiple instances of string1 and string2 , so in terms of overcounting, each instance of string2 should only be considered a single possible "hit" (if its within the lower- and

graphics - Composition: how to make a day and night world map?

Given the following world images: night = Import["http://eoimages.gsfc.nasa.gov/images/imagerecords/55000/55167/earth_lights_lrg.jpg"] day = Import["http://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57752/land_shallow_topo_2048.tif"] how would you use Mathematica to create an accurate “day and night map” (examples here and there ) of the Earth for a given date and time? Answer Let me first name your maps correctly (you switched night and day maps): night= Import["http://eoimages.gsfc.nasa.gov/images/imagerecords/55000/55167/earth_lights_lrg.jpg"]; day= Import["http://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57752/land_shallow_topo_2048.tif"]; The images have different sizes: ImageDimensions[day] (* ==> {2048, 1024} *) ImageDimensions[night] (* ==> {2400, 1200} *) so, I rescale the night image. Artefacts (if any) will probably be less visible there. night = ImageResize[night, ImageDimensions[day]]; Now, for the calculation

calculus and analysis - Variable integration limits over real numbers only

I have a simple question regarding this code: Maximize[{Integrate[1/(10 - e) Integrate[((x - 5)/(10 - 5))^(9)*5/x, {x, 5, y}] , {y, e, 10}], e >= 0, e <= 10}, e] I get the following error message: "Unable to prove that integration limits {10,e} are real. Adding assumptions may help." I tried some things already mentioned in other questions, but I didn't get it to work. Any tips? Answer Adding Assumptions -> y > 0 in the outer-most integral gives Maximize[{Integrate[1/(10 - e) Integrate[((x - 5)/(10 - 5))^(9)*5/x, {x, 5, y}] , {y, e, 10}, Assumptions -> y > 0], 0 <= e <= 10}, e] // Simplify {1879/504 - Log[32], {e -> 0}} N @ % {0.262439, {e -> 0.}} although with warnings: Integrate::pwrl: "Unable to prove that integration limits {10,e} are real. Adding assumptions may help. and Maximize::wksol: Warning: there is no maximum in the region in which the objective function is defined and the constraints are satisfied; a

dynamic - Slow image manipulation

This is some extremely simple code that shows an image and manipulates a circle (that will be used to select a region of the image to analyze). All those Dynamic s eliminate some terrible lag, I understand the one for the circle, but why are the other necessary? theImage = pickAnImage; (*mine is 368 by 252*) Manipulate[ circularSelector = Graphics[{Yellow, Dynamic[Circle[center, radius]]}]; xRange = Dynamic[{center[[1]] - radius, center[[1]] + radius}]; yRange = Dynamic[{center[[2]] - radius, center[[2]] + radius}]; Column[{Show[theImage, circularSelector], xRange, yRange}], {{center, {184, 126}}, {0, 0}, {368, 252}, 1, Locator, Appearance -> None}, {{radius, 50}, 2, 100, 1, Appearance -> "Labeled"}] Consider now adding one line of code to show the section of the image in the selection, something like ImageTake[theImage,xRange,yRange], Well, that doesn't work. It works if the Dynamic s are removed from the definition of xRange and yRange , but then a

system of differential equations in Mathematica

How can I formulate the addressed system of differential equations in Mathematica for to find a general solution for $f[x_1, x_2, x_3, y_1, y_2, y_3]$. https://math.stackexchange.com/questions/1530498/system-of-differential-equations-in-mathematica Answer I have transcribed the code from the image, and corrected the errors identified by the OP, MichaelE2 and me: p = D[f[x1, x2, x3, y1, y2, y3], x1]; q = D[f[x1, x2, x3, y1, y2, y3], x2]; r = D[f[x1, x2, x3, y1, y2, y3], x3]; o = D[f[x1, x2, x3, y1, y2, y3], y1]; x = D[f[x1, x2, x3, y1, y2, y3], y2]; a = D[f[x1, x2, x3, y1, y2, y3], y3]; equ1 = 2 x1 p + 2 x2 q + 2 x3 r - y1 o - y2 x - y3 a; equ2 = -x1 p - x2 q - x3 r + 2 y1 o + 2 y2 x + 2 y3 a; equ3 = (x1 (x1 + 2 x2 + 2 x3)) p + (x2 (x2 + 2 x3)) q + (x3^2) r - (y1 (x2 + x3)) o - y2 x3 x; equ4 = (y1 (y1 + 2 y2 + 2 y3)) o + (y2 (y2 + 2 y3)) x + (y3^2) a - (x1 (y1 + y2 + y3)) p - x2 (y2 + y3) q - x3 y3 r; DSolve[{equ1 == 0, equ2 == 0, equ3 == 0, equ4 == 0}, f, {x1, x2, x3, y1, y

mathematical optimization - Minimizing using indices, error: Part::pkspec1: The expression cannot be used as a part specification

I want to use Minimize where the variables to minimize are indices pointing into an array. Here a MWE that hopefully shows what my problem is. vars = u@# & /@ Range[3]; cons = Flatten@ { Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 <= # <= 3 & /@ vars }; vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; Minimize[{Total@((vec1[[#]] - vec2[[u[#]]])^2 & /@ Range[1, 3]), cons}, vars, Integers] The error I get: Part::pkspec1: The expression u[1] cannot be used as a part specification. >> Answer Ok, it seems that one can get around Mathematica trying to evaluate vec2[[u[1]]] too early by using the function Indexed[vec2,u[1]] . The working MWE would then look like the following: vars = u@# & /@ Range[3]; cons = Flatten@{ Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 <= # <= 3 & /@ vars}; vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; NMinimize[

list manipulation - Why does this nested sum appear to sleep between iterations?

I have a weird performance problem in a nested sum, which I've reduced to the following test case: testTab = Table[1.`20, {i, 188}, {j, 301}, {k, 20}]; test[] := Sum[testTab[[1, 1, 1]] Sum[testTab[[1, 1, 1]], {n, 1, 250}], {m, 1, 10}] Monitor[test[], {n, m}] Here the output from Monitor is {n, 1} for a second, then it changes to {n, 2} , and so on until I get the result of 2500.0000000000000000 . Obviously, table accesses shouldn't be that slow. Even more interestingly, if I change the summation limit of the inner sum from 250 to 249 or smaller, I don't get this slowdown, the result appears almost instantly. I can even make table dimensions way larger, but this 250→249 transition still results in drastic performance difference. What's happening here? Is it a bug? I'm using Mathematica " 11.1.0 for Linux x86 (32-bit) (March 13, 2017) ", but this problem also happens on " 9.0 for Linux x86 (32-bit) (November 20, 2012) " and on " 11.0.1 fo

list manipulation - Faster "stuttering" accumulate?

Given some list of arbitrary precision numbers, e.g. (actual lists are 1M+ elements long): test={0, 2, 2, 47839283, 2, 0, 0, 2, 0, 1, 2, 0} I need to accumulate the list, but where a specified element value is treated as "clear", that is, the accumulation is reset to zero at that point in the list and continues. With the above example, using zero as the "clear", the result would be e.g.: {0, 2, 4, 47839287, 47839289, 0, 0, 2, 0, 1, 3, 0} I'm using Function[{lst, clr}, FoldList[If[#2 == clr, 0, +##] &, lst[[1]], Rest@lst]][test, 0] Seems pretty snappy, wondering if there's a more efficient way of doing this.

export - Exporting HTML code to file.html

I've got a problem with re-saving html code. Lets create html file: SetDirectory[NotebookDirectory[]]; Export[ "test.html", Column@{"Plot", Plot[Sin@x, {x, 0, Pi}, ImageSize -> 200]} ] Now, I want to import this file, for example to change some links inside. How to re-export this modyfied code into html in the simplest way? My way is a walkaround but it works: Export["test.txt", Import["test.html", "Source"]] (*lets skip modification part*) DeleteFile["test.html"] RenameFile["test.txt", "test.html"] I do not know html almost at all so I will be grateful for some help. This question is related to "How to save a web page..." wich is also worth looking at. Answer How about something like this: h = Import["/tmp/htmlsource.html", "Text"]; Export["/tmp/output.html", StringReplace[h, a : " StringJoin[a, ToUpperCase[href], z]], "Text"] This

finite element method - NDEigensystem for structural vibration

Having installed version 11 I thought I would check an old Stack Exchange vibration problem using NDEigensytem. The old problem was Test a wooden board's vibration mode and I think this was before NDEigensystem and thus very complicated. However I get different answers to the old question and a warning I don't understand. User21 had done all the hard work in the previous question part of which I copy now to make the mesh. The code is as follows. First define the stress operator for 3D structures Needs["NDSolve`FEM`"] ClearAll[stressOperator, u, v, w, x, y, z]; stressOperator[ Y_, \[Nu]_] := {Inactive[ Div][{{0, 0, -((Y*\[Nu])/((1 - 2*\[Nu])*(1 + \[Nu])))}, {0, 0, 0}, {-Y/(2*(1 + \[Nu])), 0, 0}}.Inactive[Grad][ w[x, y, z], {x, y, z}], {x, y, z}] + Inactive[ Div][{{0, -((Y*\[Nu])/((1 - 2*\[Nu])*(1 + \[Nu]))), 0}, {-Y/(2*(1 + \[Nu])), 0, 0}, {0, 0, 0}}.Inactive[Grad][ v[x, y, z], {x, y, z}], {x, y, z}] + Inactive[ Div][{{

algorithm - Extracting values with multiple keys

I want to extract sorted data from a huge database based upon two (or more) keys in a very timely manner. Here is a reproducible toy example for two keys only: n = 10^5; keys = RandomInteger[{1, 100}, n]; vals = RandomReal[{0, 1}, n]; data = Transpose[{keys, vals}]; The fastest "traditional" way I' ve found: result1 = Sort @ Cases[data, {25 | 73, r_} :> r]; Much much faster is a V10 solution: assoc = Merge[Association /@ Rule @@@ data, Identity]; (I use Merge to allow for duplicate keys, and the time cost of getting assoc is not important to me). result2 = Sort[assoc[25] ~ Join ~ assoc[73]]; result1 == result2 True Speed comparison: Do[Sort @ Cases[data, {25 | 73, r_} :> r], {100}]; // AbsoluteTiming // First 2.017115 Do[Sort[assoc[25] ~ Join ~ assoc[73]], {100}]; // AbsoluteTiming // First 0.030002 Certainly one reason to upgrade, but two or more questions remain: (a) Could this code be improved ? (b) And, passing to n = 10^6 , result1 still works, but result2

calculus and analysis - Stop the Zeta function from evaluating

I have a function F whose power series i want to find using Series . It gives me the result I want, except there is a term of $\pi^4/10800$, and i want it to tell me if the result is Zeta[2]^2/300 or Zeta[4]/120 . Is there a way to force the Zeta function to not evaluate? F[x] = Integrate[Binomial[x, k], {k, 0, x}]; Series[F[x], {x, 0, 3}] // TeXForm $x+\frac{\pi ^2 x^3}{36}+O\left(x^4\right)$ I want the output to be $x+x^3\frac{\zeta(2)}{6}$ instead. Answer You could Block Zeta so that it doesn't evaluate: Block[{Zeta=Inactive[Zeta]}, Series[F[x],{x,0,6}] ] //TeXForm $x+\frac{1}{6} x^3 \operatorname{Zeta}(2,1)-\frac{1}{6} x^4 \operatorname{Zeta}(3)+\frac{1}{60} x^5 \left(\operatorname{Zeta}(2,1)^2+9 \operatorname{Zeta}(4,1)\right)+x^6 \left(-\frac{1}{30} \operatorname{Zeta}(3) \operatorname{Zeta}(2,1)-\frac{2 \operatorname{Zeta}(5)}{15}\right)+O\left(x^7\right)$

graphics3d - Möbius transformations revealed

Möbius Transformations Revealed is a short video that vividly illustrates the simplicity of Möbius transformations when viewed as rigid motions of the Riemann sphere. It was one of the winners in the 2007 Science and Engineering Visualization Challenge and the various YouTube versions have been viewed some 2,000,000 times. In the still image below, the colored portion corresponds to a simple square in the plane. The colored portion on the sphere is the image of the square in the plane under (inverse) stereographic projection; the sphere is then rotated into the position shown and finally projected back to the plane. The colored portion on the plane is the image of the original square under a Möbius transformation. How can we implement this in Mathematica ? Is it possible to create a dynamic version with Manipulate that allows us to interact with the image? Can we recreate a portion of the movie? Obviously, Mathematica can't create images of the quality of the original (which wa