New answers tagged

0

You could use Clip: al[ Clip[x, {3, Infinity}] ]


3

I stopped debugging after the first line. The problem is you need p1 : {x1_, x2_} and you have p1_ : {x1_, x2_} where {x1_, x2_} is Optional for missing entry. Which makes xi_ not associated with an input at all, they will appear only when the input is missing. Unless you fix your code you can only use pi references. But the very outer statement is If ...


2

Maybe I misunderstood this problem? My solution is much more simpler(and readable, cause I'm simply too stupid to understand @jkuczm's code. I'll appreciate that if you may kindly add some explanation?) than @jkuczm's solution, but they generate the same result........ Code first: p[e_] := If[AtomQ@e, If[NumericQ@e, e, e[##]], p /@ e] f[e_] := Evaluate[p[e]...


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{...


5

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 ...


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 ...


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 ...


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.


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"]]


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, {...


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[...


1

Using jkuczm comment together with chuy's answer, I have a satisfactory solution. Consider the following example expression (f is a symbolic operator introduced in OP's question): expr = Cos[ f[Sin[p x^2], x] ] When using D, set option NonConstants->{f} to prevent it from operating on f. This works for any expression where f appears arbitrarily deep....


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

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 ...


0

In this case, the use of PatternSequence seems to be unnecessary. I think that the following achieves the desired result: rule2 = HoldPattern[func[a | b, c_][({x_} | x_), z_]] :> {c, x, z} func[a, 2][1, 3] /. rule2 func[a, 2][{1}, 3] /. rule2 In response to the edited question, I think the following works rule3 = func[a | b, c_][{x__} | (x__)] :> {...


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


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::...


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`"...


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 ...



Top 50 recent answers are included