Tag Info

29

A manual way of doing it is: Plot3D[With[{ϕ = ArcTan[x, y], r = Sqrt[x^2 + y^2]}, 0.3 Sin[2 π r + ϕ]] , {x, -5, 5}, {y, -5, 5} , BoxRatios -> Automatic, Mesh -> None, PlotPoints -> 25, MaxRecursion -> 4 ] The reasoning behind the code is as follows: We know we want to start with some ripples radiating outwards, something like $$\... 16 You may want to plot z(r, fi) = sin (r + fi) p = 20; Plot3D[ Evaluate @ Sin @ Tr @ CoordinateTransform["Cartesian" -> "Polar", {x, y}], {x, -p, p}, {y, -p, p}, PlotPoints -> 100, BoxRatios -> Automatic ] p = 30.; n = 9 10^4; pts = Catenate@Array[List, Sqrt[n] {1, 1}, {{-p, p}, {-p, p}}] + RandomReal[.2, n]; MapThread[ Append, {... 12 Implementation This is indeed an important problem. It is usually best to have a separate function testing various options. Here is the solution I propose: a wrapper that would factor out the testing functionality from the main function. Here is the code: ClearAll[OptionCheck]; OptionCheck::invldopt = "Option 1 for function 2 received invalid value 3"... 8 After some digging, I found this symbol is related to the undocumented GraphComputationGraphElementDataDumpRawNetworkGraphData.You can find the usages you mentioned and much more by typing the code: Needs["GeneralUtilities"] PrintDefinitions[GraphComputationGraphElementDataDumpRawNetworkGraphData] Here is preview of a portion of definitions, you can ... 7 I think this is good case for TagSetDelayed. Rather than redefining D, you associate f with the desired upvalue. f /: D[f[exp_, x_], p_] := f[D[exp, p], x] D[f[Sin[p x^2], x], p] (* f[x^2 Cos[p x^2], x] *) 6 You may make use of the built-in index caching for Entity objects; "WolframLanguageSymbol". lookupOptionFunction[optionName_String] := ToExpression /@ EntityValue[EntityList[ Entity["WolframLanguageSymbol", {EntityProperty["WolframLanguageSymbol", "OptionNames"] -> optionName}]], "Name"]] First run after creating ... 6 It seems like a glitch in the pattern matcher, occuring whenever named patterns appear in a head and PatternSequence appears at level 1 in the body. Null /. f_[PatternSequence[x, y]] -> 0 Pattern::patvar : First element in pattern Pattern[1, _] is not a valid pattern name. >> When there are multiple named patterns in the head there are additional ... 5 Preamble Leonid's method is new to me and quite interesting. I expect that as with most of his methods it is well reasoned and has advantages that are not immediately apparent. Nevertheless I also find value in alternative methods, so here is one of mine. I shall use his example code so that these methods may be compared directly. Boilerplate General::... 5 Here is another way that looks more like sand spirals with the tide coming in: With[{d = 42, n = 150}, ReliefPlot[ Cos@Table[ Through[(Abs + Arg)[x + I y]], {x, -d, d, d/n}, {y, -d, d, d/n}]]] As a side note, if you want to see a physics phenomenon where such Archimedean spirals occur, you may find this link to my web page interesting. 4 It's not clear that your question is about the Mathematica software, but just in case, here's a stab at it: Clear[converter] converter[s_String] := FromDigits[Characters[s], 26] /. Thread[CharacterRange["A", "Z"] -> Range[26]] converter["AB"] (* Out: 28 *) 4 Here is an expanded version of JM's implementation of your method that he proposed in comments. As an aside, I found this interesting write-up by Michele Benzi (Emory University) on Cimmino, his method and other accomplishments, and the Italian school of numerical analysis in the 1920s-30s; a very interesting read. I first propose a version using the ... 4 Any wave form could be used: ParametricPlot3D[{r Cos[t], r Sin[t], 0.2 TriangleWave[r - t/(2 Pi)]}, {r, 0, 6}, {t, 0, 2 Pi}, Mesh -> None, PlotPoints -> {121, 30}] ParametricPlot3D[{r Cos[t], r Sin[t], Sin[r - t]}, {r, 0, 60}, {t, 0, 2 Pi}, Mesh -> None, PlotPoints -> {121, 30}] Etc. 4 Thies's solution is excellent. This was the best I could do with a logarithmic spiral: With[{ψ = 87°}, Plot3D[Tanh[(x Sin[Tan[ψ] Log[x^2 + y^2]/2] + y Cos[Tan[ψ] Log[x^2 + y^2]/2])/10], {x, -20, 20}, {y, -20, 20}, Axes -> None, BoundaryStyle -> None, Boxed -> False, BoxRatios -> Automatic, ColorFunction ... 4 This is a form of memoization by dynamically defining a Pattern with the results of the executed Expression as clarified by @ciao. The standard form is documented in Functions that remember values they have found and looks like: f[x_]:=f[x]=rhs So as an example: f[x_] := f[x] = f[x - 1] + f[x - 2] behaves the same as i:f[x_] := i = f[x - 1] + f[x - ... 4 I think this gives what you want: We construct the integral inside the definition of H by adding another ODE to the NDSolve system, which I called logH. This in fact calculates the integral from ic, not from 0. So to define H we need to subtract logH[0] from logH[t] before exponentiating. This should be a much more accurate (and faster) way of computing ... 3 You can replace your TemplateApply with either TemplateApply["Print[`];", i++] or StringJoin["Print[", ToString[i++], "];"] There is also a quick fix that is not recommended, which is to replace Module by Block. 3 How about adding some assumptions (I think the following is reasonable): res = Integrate[(x1 + x2 - 1)*(Boole[ x1 + x2 >= s && x1 >= t1 && x2 >= t2]), {x1, 0, 1}, {x2, 0, 1}]; FullSimplify[res, 0 < s < 1 && 0 < t1 <= t2 < 1]$$\begin{cases} \frac{1}{2} (\text{t1}-1) (\text{t2}-1) (\text{t1}+\text{...

3

Module[{n = 15, pts}, pts = Table[{θ Cos[θ], θ Sin[θ], 0}, {θ, 0, n π, π/20}]; Graphics3D[{GrayLevel[.75], Tube[pts, π]}, ClipPlanes -> {0, 0, 1, 0}, Boxed -> False, Lighting -> "Neutral"]]

3

This is not a full answer, but the problems I mention below must be corrected before your code can be executed. This is not to say that the code will work even when these problems are solved. Correcting them is a necessary condition, not a sufficient one. The function ge is not defined. Your While has invalid semantics. Perhaps you meant to write While[...

2

I don't see any reason to use Module for what you seem to asking. I suggest g[expr_, var_Symbol] := If[FreeQ[expr, var], $Failed, expr /. var -> var + 1] Then g[n^2, n] (1 + n)^2 g[2 Sqrt[x] + y^x, x] 2 Sqrt[1 + x] + y^(1 + x) but g[a + Sqr[x], y]$Failed

2

You can use an intermediate expression that can be returned by your function, not printed as side effect. Then you can use \$Post to post-process this returned expression, so that it'll result in multiple printed cells. ClearAll[multipleCellsOutput, printMultipleCellsOutput] printMultipleCellsOutput = # /. multipleCellsOutput[cells_List] :> Scan[...

2

I agree that behavior of Return with one or no arguments can be unintuitive, but usage of Return with two arguments, where second argument is head of expression you want to return from, is pretty straightforward. ClearAll[f] f[x_] := Module[{a = x}, (*...;*) If[a < 5, Return[a, Module]]; (*...*) a + 1000 ] f[2] (* ...

2

Consider the following contrived example. chooser := Catch[#, "me"]&[Unevaluated @ Module[{u = RandomChoice[{1, 2, 3}]}, Switch[u, 1, Throw[1, "me"], 2, Throw[2, "me"], 3, Throw[3, "me"]]]] SeedRandom[42]; Table[chooser, 5] {2, 3, 2, 1, 1} Does that give you an idea on how you might write your code in a style ...

1

I'm worried that your problem is intractable because of the large number of rows in your parameter file. Processing a few rows would be no problem, where few is defined as a thousand or so. Also if you were to accumulate lists of all the target values optcost, optbud, and optq, what would you do with such long lists? Each would have 1.5M elements according ...

Only top voted, non community-wiki answers of a minimum length are eligible