Skip to main content

Posts

Showing posts from June, 2014

differential equations - PDE with Stefan Conditions, a.k.a variable boundary

I want to solve the one-dimensional one-phase Stefan problem, but I don't know how to make Mathematica understand the conditions. If you are not familiar with what I'm asking please refer to this wikipedia article: http://en.wikipedia.org/wiki/Stefan_problem#Mathematical_formulation This is what I have so far. Clearly, it doesn't work. NDSolve[ {D[u[x, t], t] == D[u[x, t], {x, 2}], (-D[u[x, t], x] /. x -> 0) == 1, u[s[t], t] == 0, D[s[t]] == (-D[u[x, t], x] /. x -> s[t]), u[x, 0] == 0, s[0] == 0 }, {u, s}, {x, 0, s[t]}, {t, 0, 10}] I hope there is someone out there with a magical code I'm using Mathematica 10 . Thanks! Answer One can do it semi-automatically. Let us introduce a normalized variable $$ \xi = \frac{x}{s(t)}, \quad \xi \in [0,1] $$ and make a simple finite difference method over $\xi$. The differential equation in new variables is ClearAll[u, s, x, t, ξ] D[u[x/s[t], t], t] == D[u[x/s[t], t], x, x] /. x -> ξ s[t] If we divide the int

list manipulation - Efficient way to combine SparseArray objects?

I have several SparseArray objects, say sa11, sa12, sa21, sa22, which I would like to combine into the equivalent of {{sa11, sa12}, {sa21, sa22}} . As an example, I have : sa11 = SparseArray[Band[{1, 1}, {4, 4 3}] -> {{ConstantArray[1, 3]}}] sa12 = SparseArray[Join[Band[{1, #}, {4, 4 3}] -> 1 & /@ Range[1, 4 3, 4]]] sa21 = SparseArray[Join[Band[{1, #}, {3, 4 3}] -> 1 & /@ Range[1, 4 3, 3]]] sa22 = SparseArray[Band[{1, 1}, {3, 4 3}] -> {{ConstantArray[1, 4]}}] I am able to generate the big SparseArray with : sa = SparseArray[Join[{Band[{1, 1}, {4, 4 3}] -> {{ConstantArray[1, 3]}}}, Band[{1, #},{4, 2 4 3}] -> 1 & /@ Range[4 3 + 1, 2 4 3, 4], Band[{4 + 1, #}, {4 + 3, 4 3}] -> 1 & /@ Range[1, 4 3, 3], {Band[{4 + 1, 4 3 + 1}, {4 + 3, 2 4 3}] -> {{ConstantArray[1, 4]}}}], {4 + 3, 2 4 3}] Is there an efficient way to achieve this in general ? Answer ArrayFlatten[{{sa11, sa12}, {sa21, sa22}}] seems to be what you need. It automatically merges ev

graphics - Encoding format used by GraphicsData?

I am trying to extract some graphics stored in PICT format from a Mathematica notebook, using a platform that doesn't support PICT. If I look at the .nb file in a plain text editor, or if I use FullForm , then I can see that the picture is stored as a GraphicsData head with a text string encoding the picture. It doesn't appear that the GraphicsData head uses Base64 or any other binary-to-text encoding that I know of off the top of my head, but I would like to be able to copy-and-paste the GraphicsData string and decode it manually. Is this possible? Does GraphicsData use a well-known encoding scheme? Answer I found an example on the web. Here is code that will convert the PICT data from the format stored in the notebook file into a .pict file that can be opened by an image viewer (e.g. Photoshop). DecodePICT[data_String] := Module[ {slash, backslash, zero, LF, CR, decode, codes, len, i}, {slash, backslash, zero, LF, CR} = ToCharacterCode["/\\0\n\r"];

calculus and analysis - Definite integral of a real function outputs complex number

I was just wondering how such an integral: Integrate[(1.2 - 0.05 x)^2 x^4 ((1 - 0.85 (1.2 - 0.05 x))^0.5 (2 + 0.85 (1.2 - 0.05 x)) - (1 + 1.7 (1.2 - 0.05 x)) ArcCos[ 0.85 (1.2 - 0.05 x)]),{x,0,8}] would output a complex number. How is so? Is this some sort of error? Should I add some sort of assumption? Or suggest an integration method (numerical)? I've tried some yet a still get a complex result. Answer There is in fact a problem with evaluating the integral Let's save the integrand: int = (1.2 - 0.05 x)^2 x^4 ((1 - 0.85 (1.2 - 0.05 x))^(1/2) * (2 + 0.85 (1.2 - 0.05 x)) - (1 + 1.7 (1.2 - 0.05 x)) ArcCos[0.85 (1.2 - 0.05 x)]); It seems there is more to the OP's integral than just why does it return complex values: Integrate[int, {x, 0, 8}] (* -1833.02 - 268.546 I *) Integrate[int, {x, 8/17, 8}] Integrate[int, {x, 0, 8/17}] % + %% (* -2101.56 + 2.15407*10^-25 I 0. + 849215. I -2101.56 + 849215. I *) NIntegrate[int, {x, 0, 8}] (* -2101.56 - 0.0000559972 I

list manipulation - Finding the period of an array of integers

A simple array of integers is given. The problem is to detect if a pattern is repeatedly occurring in the array, and find the length of that pattern. For example, for {19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6} pattern {19, 6} should be detected and its length is 2 . For {73, 7, 4, 73, 7, 4, 73, 7, 4, 73, 7, 4, 73, 7} pattern {73, 7, 4} should be detected and its length is 3 . (at the end of the array there need not be the complete pattern, but the pattern should start at the beginning of the array) For {73, 7, 4, 7, 2, 6, 7, 2, 7, 73, 9, 17, 7, 7} the whole array is the pattern and its length is 14 . Related links MATLAB function seqperiod() SO question on cycle detection Related question on this site Wikipedia article on cycle detection Answer This uses partitioning, with padding if required, to make sublists. f = Module[{b, c = 1}, While[Length[b = Union@Partition[#, c, c, {1, 1}, Take[#, c]]] > 1, c++]; {Length@First@b, First@b}] &; Example f@{73, 7, 4, 73, 7, 4,

import - How to read CDF (Common Data Format) file?

I don't understand, what Import does with CDF. If I enter In[17]:= data = Import[ExampleFile] Out[17]= {"Pose"} what I can do with returned object? How can I return Pose entry only? If I try to specify this as element name as string, I am failing: In[18]:= data = Import[ExampleFile, "Pose"] During evaluation of In[18]:= Import::noelem: The Import element "Pose" is not present when importing as NASACDF. Out[18]= $Failed UPDATE I noticed, that it showed entity name in quotes. In notebook it looks different: i.e. w/o quotes. UDPATE 2 Shared example: https://drive.google.com/open?id=0By8pZ9a2478YOGlhZUlRU3VNb28 UPDATE 3 Apparently Mathematica has a bug here, because the data returned is reshaped incorrectly. Here is Matlab transcript, reading the same file: >> data = cdfread(ExampleFile,'Variable', {'Pose'}); >> data = data{1}; >> size(data) ans = 992 96 >> data(1,1:5) ans = 1×5 single row vector -287.2470

files and directories - Where can I permanently modify Directory[]?

First I set SetDirectory["F:\\learning_mma"];Directory[](*ok,success*) and then I quite the kernel: Quit[] an then Directory[] it output the "C:\\Users\\Administrator\\Documents" . So how can I modify Directory[] permanently? Answer You can run SetDirectory in the kernel initialization file, init.m . You'll find it here: SystemOpen@FileNameJoin[{$UserBaseDirectory, "Kernel"}]

geometry - Projection of a 3d curve to 2d

This question is related to: How to obtain the coordinates of the intersection line of two surfaces? Read the link first. First, I have tried MaxCellMeasure->0.5 , MaxCellMeasure->{"Length"->0.5} and MaxCellMeasure->{"Area"->0.5} , and change the number 0.5. It seems that the numbers of point doesn't change. Secondly, it's very fast to run your code, but it takes about minutes to run my code with my f[x,y,z] , g[x,y,z] . And this is my code: Clear[f,g]; f[x_,y_,z_,t_]:=x^2+y^2+(z-1)^2-t^2/4; g[x_,y_,z_]:=Piecewise[{{(x-1/2)^2+y^2+z^2-1/16,(x-1/2)^2+y^2-1/16<=0&&z>=0}},z]; reg=DiscretizeRegion[ImplicitRegion[{f[x,y,z,2]==0, g[x, y, z] == 0}, {x, y, z}]]; MeshCoordinates[reg] Is it because I used Piecewise in g function that it needs more time to run the code? Third, what I want to do next is below. In fact, I want to plot the projection of the intersection line on xy plane. And this is point projection, as shown below Connect (0,

list manipulation - Undocumented form for Extract

Prompted by a comments conversation here , here's an interesting (and often performance enhancing) use of Extract : target = Join[Range[100], {{1, 2, 3, Range[20]}}]; Rest@Extract[target, {{{}}, {2 ;; 10 ;; 2}, {-1, -1, 1 ;; -1 ;; 2}}] (* {{2, 4, 6, 8, 10}, {1, 3, 5, 7, 9, 11, 13, 15, 17, 19}} *) Prepending the {{}} to the extraction list appears to suppress the error message one would otherwise get attempting to use Span , and it appears that most any valid position/span construct can be used in the extraction list. The extracted list has an empty list as first element (hence the use of Rest ). Prepending just {} makes the first element the original list. I've often found this useful instead of mapping over a list of spans (and faster). This seems similar to the undocumented extension to MapAt As noted by Mr. Wizard, this does not appear to work in V7, I'm curious what versions it works in.

plotting - Generating high quality charts in Mathematica for use in LaTeX and Word

I frequently have a probelem using my charts in reports because the text (axes labels and tick marks) look low resolution (fuzzy). When I export my charts, i export them as PNG files. Unless I'm mistaken, this is the correct file format for vector graphics. In Mathematica , the charts look great at any size, but when I export and drag them into Word, they don't look nearly as nice any more. Does any one have any tricks they use to use the Mathematica charts in applications like Word? Answer You don't say whether you want high quality for printing or for viewing on screen. Unfortunately, in Word, you often have to pick one or the other. Which is not always an easy decision, for example if you're emailing a report to someone and you don't know if they will read it on screen or print it out. In my experience the best approach for good quality printing from Word is to use a bitmap (raster format), but make sure you export at high resolution. The main advantage is tha

plotting - How to plot customly-shaped set of 3D points each connected to its neighbors?

Consider the following code: ListPointPlot3D[ Flatten[#, 1] &@ Table[{x, y, 1}, {x, 0, 5, 5/60}, {y, Sin[x], Cos[x] + 3, ( Cos[x] + 3 - Sin[x])/60}], PlotRange -> All] If I change ListPointPlot3D to ListPlot3D , I get the following: Apparently, ListPlot3D connects the points not in an expected way. How to plot the set so that the neighboring points were connected with each other, not the far ones? Answer If the points form a deformed rectangular grid, then you can use the method below; otherwise, the methods of the following question should work: DelaunayMesh in a specified closed region - creating a concave hull from a set of points For a tensor grid of points: pts = N@Table[{x, y, Cos[x] Sin[y]}, (* varying height *) {x, 0, 5, 5/60}, {y, Sin[x], Cos[x] + 3, (Cos[x] + 3 - Sin[x])/60}]; With[{p = Flatten[pts, 1]}, Graphics3D[ GraphicsComplex[ p, {EdgeForm[], ColorData[97][2], Polygon[ Flatten[#][[{1, 2, 4, 3}]] & /@ Flatten[Partition[

evaluation - Why the Block command does not forget the $ContextPath variable

I do not understand this behavior: method[args_] := (* forget the context path *) Block[{$ContextPath}, (* should given nothing, right? *) Print["cpath=", $ContextPath]; ... but when evaluated it gives the full context path (i.e. it does not forgets it). Why is that? This is against everything I (seem to) know about the Block function. Answer If I try this, everything gets removed except for {System`,Global`} : In[1]:= $ContextPath Out[1]= {"PacletManager`", "QuantityUnits`", "WebServices`", "System`", "Global`"} In[2]:= Block[{$ContextPath}, Print[$ContextPath]] During evaluation of In[2]:= {System`,Global`} My guess is that this is a special exception which is implemented to make $ContextPath usable like this: Block[{$ContextPath}, Needs["SomePackage`"]] This loads the package without adding it to the context path. It's quite useful with Combinatorica in version

What is an efficient way of selecting multiple colors via Manipulate?

Background: The following snippet is what I (intend to) use in a Manipulate form where up to 12 different colors can be selected: Manipulate[{sliderCol1}, Row[{"Kleur 1: ", ColorSlider[ Dynamic[sliderCol1] , AppearanceElements -> {"SwatchSpectrum"}, ImageSize -> {200, 40}, BaselinePosition -> Scaled[.25]]} ] ] To make this work with fields sliderCol1 to sliderColn (where $n$ = 2, …, 12), I see no other option than copying the code in Row so many times. Question: Is there a less verbose way of implenting a multiple (here 12) color selector using color sliders? Answer With this one you just click the circle to be color-edited. No need to pick an index number first. DynamicModule[{x = 1}, Manipulate[c[[x]] = color; Grid[ Table[ Setter[Dynamic[x, (color = c[[#1]]; x = #1) &], i*4 + j, Graphics[{FaceForm[c[[i*4 + j]]], Disk[]}, ImageSize -> 40] ], {i, 0, 2}, {j, 4} ] ], {color, Red}, Initializa

performance tuning - Why does iterating Prime in reverse order require much more time?

Say I would like to display the $10$ greatest primes that are less than $10^5$. I could do the following: AbsoluteTiming[ M = 10^5; m = PrimePi[M]; prms = Prime[#] & /@ Range[1, m]; prms[[#]] & /@ Range[-1, -10, -1] ] And the result comes out : {0.0156250, {99991, 99989, 99971, 99961, 99929, 99923, 99907, 99901, 99881, 99877}} But if I tried to do in in reverse, AbsoluteTiming[ M = 10^5; m = PrimePi[M]; prms = Prime[#] & /@ Range[m, 1, -1]; prms[[#]] & /@ Range[1, 10] ] the process takes a whole lot longer: {0.6250000, {99991, 99989, 99971, 99961, 99929, 99923, 99907, 99901, 99881, 99877}} Using the second method, I can't even increase M to $10^6$, as the program takes extremely long to execute. Can anybody offer some insight into this ? $\;$ Am I essentially not doing the same thing in both cases ? Answer Given a large n , to find k largest primes below n (as well as above) the best approach uses NextPrime (it has been added to Mathematica 6 ) : Nex

plotting - How to align 3 plots horizontally without spacing?

Suppose I have 3 plots a , b and c , where a = Plot[x, {x, 0, 1}, Frame -> True, FrameTicks -> {{All, None}, {All, None}}, PlotRangePadding -> None]; b = Plot[-x, {x, 1, 2}, Frame -> True, FrameTicks -> {{None, All}, {All, None}}, PlotRangePadding -> None]; c = Plot[-2 + 3 x, {x, 2, 2.5}, Frame -> True, FrameTicks -> {{None, All}, {All, None}}, PlotRangePadding -> None, Frame -> True, FrameTicks -> All]; Now I want to combine them into one, exactly as what this figure depicts. That is, the final result looks like this, on which the lines connected to each other: I tried to use this plotGrid function here : plotGrid[{{a, b, c}}, 500, 300, ImagePadding -> 40] However, the function is intentionally written for even width figures. What I want to do is different width, proportional to each plot's x ranges, i.e., width of a $:$ b $:$ c =$1:1:0.5$. I have also tried other ways like this : c = Plot[-2 + 3 x, {x, 2, 2.5}, Frame -> True

graphics - How to plot an emission spectrum?

If I have a list of data with various wavelengths in nanometers, how would I plot them on a graph so it looks like this: So far I have managed to plot a spectrum in DensityPlot , but I have no idea how to hide values that are not in my data set. I do not know if this is the correct method. DensityPlot[x, {x, 300, 800}, {y, 0, 1}, ColorFunction -> ColorData["VisibleSpectrum"], ColorFunctionScaling -> False, AspectRatio -> .3] I should also note that my data is nonintegral. Answer You can also construct the image from Graphics primitives, which ultimately may give you more control: spectrum[list_List] := Graphics[ {Thickness[0.005], ColorData["VisibleSpectrum"][#], Line[{{#, 0}, {#, 1}}]} & /@ list, PlotRange -> {{380, 750}, {0, 1}}, PlotRangePadding -> None, ImagePadding -> All, AspectRatio -> 1/5, ImageSize -> Large, Axes -> None, Frame -> {True, False, False, False}, Prolog -> Rectangle[{0, 0}, {1000, 1}] ] Using

mac os x - MathLink linking error after OS X 10.9 (Mavericks) upgrade

After macosx 10.9 mavericks upgrade i have a compilation problem, you can see below. Even the examples given in /Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/MathLinkExamples are not compiling anymore. It throws an error about the architecture. I also followed the solution given by MathLink compile errors , reinstalling the Xcode and command line tools. It didnt work. I also checked the libMLi3.a for architecture and seems like it is ok libMLi3.a: Mach-O universal binary with 2 architectures libMLi3.a (for architecture i386): current ar archive random library libMLi3.a (for architecture x86_64): current ar archive random library and clang/gcc as well Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) Target: x86_64-apple-darwin13.0.0 Thread model: posix gcc -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3s

programming - How do you set attributes on SubValues?

SubValues , as discussed in a previous question , are declared as follows f[x_][y_] := {ToString[Unevaluated[x]], ToString[Unevaluated[y]]} But, attempting to use SetAttributes on f only affects the DownValues of f during evaluation, not the SubValues . In other words, if HoldAll is set on f , then only x , in the above code, is held. In code, SetAttributes[f, HoldAll] f[ 1 + 2 ][ 3 + 4 ] (* ==> { "1 + 2", "7" } *) Attempting to use SetAttributes on f[x] results in the error SetAttributes::sym: "Argument f[x] at position 1 is expected to be a symbol." and, similarly, for f[x_] simply because neither are symbols. A work around is not to set a SubValue directly, but, instead, return a pure function and use the third argument to set the attribute, as follows SetAttributes[g, HoldAll] g[x_] := Function[{y}, {ToString[Unevaluated[x]], ToString[Unevaluated[y]]}, {HoldAll} ] g[ 1 + 2 ][ 3 + 4 ] (* ==> {"1 + 2"

plotting - Exporting to eps loses font information

I have seen this question before, but with no real solution. The problem is, I have a plot that uses greek characters (sigma to mark first and second standard deviations) and other symbols (e.g. Angstroms), but this information does not translate into the graphs. This is a MWE, obviously messy since I just want to show that I'm not getting the characters and a lot of the options are remnants from the original plot. Show[{Plot[Sin[x], {x, 0, 5}], Graphics[Text[Style["+1σ", FontSize -> 14], {4, 0.4}]]}, Frame -> True, FrameLabel -> {{"Å", None}, {"x", None}}, FrameTicks -> Automatic, BaseStyle -> {FontSize -> 14, FontFamily -> "Helvetica"}] (In the last line, I use "BaseStyle" because I saw on here as a potential solution, but it does nothing.) Here is what the above code outputs in PNG: As you can see, I need the sigma and the Angstrom symbols to appear. However, when exported to EPS, I get (converted) Th

evaluation - What is the Difference Between Rule (->) and RuleDelayed (:>)?

I am new to Mathematica so this question may seem rudimentary. Sorry for that! :) I want to implement the well-known property of Kronecker's Delta $$\Sigma_{i=1}^{n} a_i \delta_{ij}=a_j,\quad 1 \le j \le n$$ So I wrote the following code KroDelProp[Eq_] := Module[{R, c, i, j, a, b}, R = Inactive[Sum][c_*KroneckerDelta[i_, j_], {i_, a_, b_}] :> (c /. i -> j); Eq /. R ] Eq = Inactive[Sum][a[i]*KroneckerDelta[i, j], {i, 1, n}] KroDelProp[Eq] (* a[j] *) So everything looks fine. But when I use Rule instead of RuleDelayed in KroDelProp then I get KroDelProp[Eq_] := Module[{R, c, i, j, a, b}, R = Inactive[Sum][c_*KroneckerDelta[i_, j_], {i_, a_, b_}] -> (c /. i -> j); Eq /. R ] Eq = Inactive[Sum][a[i]*KroneckerDelta[i, j], {i, 1, n}] KroDelProp[Eq] (* a[i] *) I read the documentation but I couldn't find out what is happening here! Can someone shed some light on this? :) I found reading this documentation very useful. Hope that it helps the future readers o

bugs - Instant kernel crash when using `+=` on `SparseArray` with repeated entries

Bug introduced in 5.2 and fixed in 10.1.0 Not sure if this is known behavior or not, but the following two lines produce an instant kernel crash (I'm using Mathematica 10.0.1 Windows 64-bit): A = SparseArray[{}, {3, 3}]; A[[1, {1, 1}]] += 1 This is just a minor modification of the following lines: A = SparseArray[{}, {3, 3}]; A[[1, {1, 2}]] += 1 which are designed to increment entries {1,1} and {1,2} of A by one. I would have expected the crash-inducing example to increment the {1,1} entry by two. Instead, I get screams of death. Any clues as to what is going on here? This slight variation produces a more apparent crash in 7.0.1: A = SparseArray[{}, {3, 3}]; A[[1, {1, 2, 3, 1, 1}]] += 1

fitting - Softmax Regression implementation

a[t_List,x_List]:=E^(t.Prepend[x,1]) hypothethis[t_List, k_, x_]:= Table[a[t[[j]], x], {j, 1, k-1}]/(1 +Sum[a[t[[j]],x],{j, 1, k-1}]) indicatorFunc[eqn_]:=If[eqn,1,0] SoftmaxRegression[x_List, y_List]:=Module[{J, vars, b, k, n}, k = Length@Union[y]; n = Length[Transpose[x]]+1; vars = Array[b, {k - 1, n}]; J[t_]:= (-1/Length[y])*(Sum[indicatorFunc[y[[i]] == k]*Log[1/(1 +Sum[a[t[[j]],x[[i]]],{j, 1, k-1}])]+Sum[indicatorFunc[y[[i]] ==j]*Log[a[t[[j]],x[[i]]]/(1 + Sum[a[t[[j]],x[[i]]],{j, 1, k-1}])],{j,1,k-1}],{i, 1,Length[y]}])+Sum[Sum[t[[i,j]]^2,{j, 1, n}],{i, 1, k-1}]; vars/.NMinimize[J[vars],Flatten@vars][[2]] ] http://ufldl.stanford.edu/wiki/index.php/Softmax_Regression I am trying to implement the softmax regression, which returns a list of coefficient for hypothethis function. And hypothethis function will gives the first n - 1 classes probability, which we can use to find the nth class's probability. I used FisherIris data, in which there are 3 classes: virsi

Hyperlink to a folder

Is there a way to Hyperlink to a folder. I know I can create link to a web address but is there a way to do this to a folder? Hyperlink@@@{ {"some web address",URL["www.wolfram.com"]}, {StatusArea["some folder","Path to folder where files are located"],File@FileNameJoin[{NotebookDirectory[],"FolderName"}]} }//Column The folder path is not working. Also StatusArea is not displaying (Do I need to change some notebook setting?). Answer With file protocol it works: Hyperlink[ StatusArea["some folder", "Path to folder where files are located"], "file://" <> $UserBaseDirectory ] I don't see the problem with status area, can you elaborate? I'm on Win7 v11.3.

graphics - create an (almost) hexagonal mesh on an ellipsoid

EDIT I edited the question in order to take into @Kuba's comment. I want to create this figure with Mathematica (in particular an almost hexagonal mesh on an ellipsoid; thanks to @Kuba I know this is not 100% possible). I use the function hexTile defined by @R.M. as his reply in 39879 . hexTile[n_, m_] := With[{hex = Polygon[Table[{Cos[2 Pi k/6] + #, Sin[2 Pi k/6] + #2}, {k, 6}]] &}, Table[hex[3 i + 3 ((-1)^j + 1)/4, Sqrt[3]/2 j], {i, n}, {j, m}] /. {x_?NumericQ, y_?NumericQ} :> 2 \[Pi] {x/(3 m), 2 y/(n Sqrt[3])}] E.g. ht = With[{ell = {7 Cos[#1] Sin[#2], 5 Sin[#1] Sin[#2], 3 Cos[#2]} &}, Graphics3D[ hexTile[20, 20] /. Polygon[l_List] :> Polygon[ell @@@ l], Boxed -> False]] How can we modify the function so that the distribution of hexagons and pentagons resembles closely that of the first image? Thanks. Answer If we compute the dual polyhedron of an appropriate triangularization of a surface we can get another pol

Pass Options to Export[]

I'm working with Options to change the look and feel of some generated Graphics by passing Options to several functions, one of them being Export[] . For example: Options[myPlot] := {Resolution -> 325, Size -> 12, FileName -> "A", PlotStyle -> Automatic}; myPlot[f_, opts : OptionsPattern[myPlot]] := Block[{fig}, (* ... some calculations here *) fig = Plot[f[x], {x, -\[Pi], \[Pi]}, Evaluate[FilterRules[{opts}, Options[Plot]]]]; fig = Show[fig, ImageSize -> OptionValue[Size]*72/2.54];+ Export[OptionValue[FileName] <> ".png", fig, FilterRules[{opts}, Options[Export]]]; Print[fig]; ] And using f[x_] := x^2 use the function as myPlot[f, Resolution -> 120, PlotStyle -> Red] The Option to plot the function in Red is passed correctly to Plot but Resolution is not passed to Export . This is of course due to the fact that Options[Export] = {} . My question is: How can I still pass Options to Export (i.e. how to determine, which are

image - How to implement a free version of WebImageSearch?

I really don't like functions that I have to pay for, if they can be implemented for free . Is there a way to get around this pay-wall for WebImageSearch ? Perhaps using some other free api or service? Update: One idea I had was to use the french search engine Qwant which has an api which is free and unlimited for now: https://api.qwant.com/api/search/images?count=10&offset=1&q=cars (but has less accuracy than Google or Bing). Answer So after being wrong about Bing being free, we'll pursue my other suggestion, which was to use the ServiceConnect framework . I demonstrate how to use it in general here . For the purposes of this, though, here's what all you need to do. Get the paclet by running this: (* If you've already installed, replace this with PacletUpdate to get the newest version *) PacletInstall[ "ServiceConnection_Qwant", "Site" -> "https://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer" ] Service

matrix - Can any one help me make my program work faster?

In order to construct the matrix h1+h2 , I have used three Table commands. I am using fxn[n1a_, n1b_, n2a_, n2b_] as a function in a loop. I need my program to be a lot faster than what it is now, since this is only a part of my main program. Could any one tell me how I can make it work faster? In other words, what are the points I should pay attention to in Mathematica, in case of timing? Description: In the original program I am using an iteration method in which I need to construct the matrix h1+h2 , calculate the new eigenvectors in each step, reconstruct the matrix h1+h2 , until I observe convergence in eigenenergies. avec , is a guessed vector, and I am using it as an initial vector to construct the matrix h1+h2 . Later on, I need to calculate the eigenvectors of this matrix, choose the vectors related to the minimum eigenvalues and put them instead of the previous avec . h1 is the kinetic term of my matrix and h2 is the exchange potential (the formula which I have used came