Hot answers tagged

23

Short answer The local variables of the form varname$... are used by the system, and it is unwise to use symbols with such names as local variables. With, like many other lexical scoping constructs, performs excessive renamings, often even in cases where it isn't strictly necessary. This probably has to do with efficiency - full analysis may be more costly....


5

First of all you shouldn't (if possible) use approximate numbers working with symbolic functionality like a very sophisticated function Reduce. Before seeking the set of your interest try to envisage the region: RegionPlot[ Abs[1/(1 + I/Sqrt[x + I y])] < 1/2, {x, -1.1, 0.5}, {y, -0.6, 1.0}] Now we can see what we are to find, i.e. ...


5

First we shall define 'the integration on a curve'. Traditionally, this is defined as integration of f.dl where dl is the length of a small part of the curve. So, using t as a medium, we can explicitly write out the curve's function on a complex plane, here let's assume it's z=2 Exp[I t]. Then we can use t, a real number, as the integration variable, which ...


4

I post this taking the OP on face value. There are many ways (of course) to do this. There is a lot to digest (for someone new to Mathematica, esp. distinguishing substance from cosmetic aspects). Setup: a = {-1, -1}; b = {1, -7} ; c = {3, 3}; array = {a, b, c}; exp = u x^2 + 2 v x y + w y^2; "Just get Mathematica to do it" (as J.M. suggested `...


4

The error message tells everything: "NMaxValue::nnum: "The function value {-0.31322198} is not a number at {s,t} = {0.6524678079740285,0.04524817776440737}"" NMaxValue[First[f[s, t]], {s, t} ∈ Rectangle[{0, 0}, {1, 1}]]


4

You can plot a constant Plot3D[{x^2 + y^2, 100}, {x, -10, 10}, {y, -10, 10}, ColorFunction -> "BlueGreenYellow"] or Plot3D[x^2 + y^2, {x, -10, 10}, {y, -10, 10}, MeshFunctions -> {#3 &}, Mesh -> 1, ColorFunction -> "BlueGreenYellow"]


4

The $ is a symbol used by Mathematica to generate local variable names for variables that are confined to a particular scope. For instance, if you run Module[{x}, Print[x]] you'll find it prints something like x$4456. This is the name Mathematica gave the variable to distinguish it from any other x's outside the Module.


4

I am not entirely sure what the aim is here. I am choosing a different ellipse. However, this could be easily changed. p3 = Plot3D[Sin[x] Sin[y], {x, -5, 5}, {y, -5, 5}, PlotStyle -> {Green, Opacity[0.5]}, Mesh -> False]; cp = ContourPlot3D[ x^2/25 + y^2/9 == 1, {x, -5, 5}, {y, -5, 5}, {z, -1, 1}, Mesh -> None, ContourStyle -> Opacity[...


3

Maybe this will make it clear: condition[vector_] := Norm[vector] < 10 f45[{x_, y_}] := {x + 1, y^2 + 1}; NestWhileList[f45, {0.1, 0.1}, condition] (* ==> {{0.1, 0.1}, {1.1, 1.01}, {2.1, 2.0201}, {3.1, 5.0808}, {4.1, 26.8146}} *) Here I defined the condition as a separate function to show how the last argument of NestWhileList is constructed. ...


3

You can use RegionFunction to specify the range. Plot3D[(-1 + w + 3 s w)/(2 (-1 + w + 4 s w)), {s, 0, 3}, {w, 0, 1}, RegionFunction -> Function[{s, w, z}, (1/4 < s <= 1/2 && 1/(4 s) < w <= 1) || (s > 1/2 && 3/(2 + 8 s) < w <= 1)]]


3

This is a bug due to the use of slots (#1, #2, ...) internally in the implementations of Derivative and of Integrate. Focus first on Derivative. Derivative[1,0][Print] prints #1#2. This means that at least one branch of the code for Derivative involves calling Print[#1,#2]. In your case, Derivative[1,0][f] calls f[#1,#2]. Focus next on Integrate The ...


3

For changing the position of the cylinder you could add a dynamic Slider. Regard that "Show" won't work within "Dynamic", so thats why I wrote the trigonometric function in the contour argument. dx = 0; dz = 0; Row[{Slider2D[Dynamic[{dx, dz}], {{-10, -10}, {10, 10}}], "dx =" Dynamic[dx], ", dz =" Dynamic[dz]}] Dynamic[ContourPlot3D[{((x + dx)/5)^2 + ((z ...


2

You might look into ContourPlot3D: p1 = ContourPlot3D[(x/5)^2 + (y/3)^2 == 1, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, ContourStyle -> LightBlue]; p2 = Plot3D[Sin[x] Sin[y], {x, -10, 10}, {y, -10, 10}]; Show[p1, p2] Of course, if you want to do a little more with this, it helps to put both in a contourplot. So, how do we get the intersection of ...


2

You may use Simplify. If $f(x)$ is a function, then Simplify[f[x]>=f[y], x>=y] should evaluate to the necessary condition for the monotonicity to hold. If necessary, you can use FullSimplify


2

You can use NestList to apply your function multiple times, but we need to modify your function for that purpose. As a first step, since we are not interested in the value of your function at the minimum, but only in the values of its arguments there, I am going to use NArgMin instead of your N@Minimize combination. We also need to redefine the Dis ...


2

I think the OP asked from a algebraic resp. beginners point of view as of calculus, so is my answer: It assume it is looking for Discriminant, fr = FunctionRange[x/(1 + x^2), x, y] $-\frac{1}{2}\leq y\leq \frac{1}{2}$ fr[[1]]; fr[[5]]; fr == x/(1 + x^2) $\left(-\frac{1}{2}\leq y\leq \frac{1}{2}\right)=\frac{x}{x^2+1}$ Plot[{x/(1 + x^2), fr[[1]...


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


2

Do you mean: ClearAll[A] Attributes@A = HoldAll; A[f[n_]] := A[f[n]] = Module[{d}, d = Numerator@f[n - 1]] I've removed the redundant Return. Module is also irrelevant here actually. Anyway, I suppose you need Module in your real problem so don't take it away. Or you need f to be arbitrary, too? Then: ClearAll[A] Attributes@A = HoldAll; A[f_[n_]] := A[f[...


2

Something like this? The red curve shows your contour line... P = Polygon[{{0, l}, {l, 0}, {d - l, 0}, {d, l}, {d, d}, {0, d}}]; d = 50; l = 10^-5; V = 10000; sol = NDSolveValue[{D[u[x, y], x, x] + D[u[x, y], y, y] == 0, DirichletCondition[u[x, y] == V, x + y == l && 0 <= x <= l && 0 <= y <= l], DirichletCondition[u[x, ...


2

EDIT It can get more complicated. Look at a contour given by r[t_] := 1 + 2 Cos[t]; Original post The result of the integral for a (reasonable) closed contour is just 2 I times the area enclosed by the contour. Proof: the integral is $$\int \left(z^*+z\right) \, dz$$ Letting $$z=x+i y$$, $$dz=dx+i dy$$ the integral becomes $$\int 2 x (dx + i dy)=...


2

Some alternatives for thought food... slist /. x_Integer:>g[x] ...or... Last@Last@Reap[Scan[Sow[g[#]]&,slist]]


2

g[w_] := w^2 + 1 slist = Range[0, 100, 1]; g[slist] {1,2,5,10,17,26,37,50,65,82,101,122,145,170,197,226,257,290,325,362,401,442,485,530,577,626,677,730,785,842,901,962,1025,1090,1157,1226,1297,1370,1445,1522,1601,1682,1765,1850,1937,2026,2117,2210,2305,2402,2501,2602,2705,2810,2917,3026,3137,3250,3365,3482,3601,3722,3845,3970,4097,4226,4357,4490,4625,...


2

There seem to be other oddities in this code. TGrad[x, y] /. {x -> pt[1], y -> pt[2]} doesn't make sense to me. You probably meant to use pt[[1]] which is shorthand for Part[pt, 1]. But even this shouldn't be needed as values of x and y should be populated from the destructuring pattern pt : {x_, y_}. More importantly deriv would appear to need a ...


1

Jens has shown you how do it an nice, readily understood way. Here is the same code written in the way that becomes idiomatic as you gain experience. f45[{x_, y_}] := {x + 1, y^2 + 1} With[{max = 2}, NestWhileList[f45, {0.1, 0.1}, Norm[#] < max &]] {{0.1, 0.1}, {1.1, 1.01}, {2.1, 2.0201}} I also want to tell you that f45 is technically a ...


1

Use Normal to get the polynomial out. Then work with it. The O[...] term can do funny things that are not obvious. In[2]:= SS = Normal[S] Out[2]= a/(1/x)^(9/2) + b/(1/x)^(7/2) + c/(1/x)^(5/2) + d x^2 In[7]:= S1 = FullSimplify[(SS/x^2 - d)*x^2] S2 = FullSimplify[SS - d*x^2] Out[7]= (c + x (b + a x))/(1/x)^(5/2) Out[8]= (c + x (b + a x))/(1/x)^(5/2) In[9]...


1

This works fine: interSpecialCycle[permutation_] := PermutationCycles[permutation][[1]][[1]] myperm = {1, 4, 2, 5, 3} list1 = SpecialCycle = interSpecialCycle[myperm] But list1 will not be callable, so I don't know what you mean by that: interSpecialCycle[myperm] returns a list. Are you saying that you currently call it several times with the same ...


1

You are almost there. Try this: q[matr_, n_, k_] := matr[[n, k]]; Now let us take a matrix: m = {{a, b}, {c, d}}; and apply the function to this matrix: q[m, 1, 2] (* b *) Done, have fun!


1

In addition I added a point animation and observed some oddly behaviour of Dynamic and ContourPlot3D. Functions and Conditions. yPath has to be defined immidiately (without ":") cause the later \ recursive defintion wouldn' t work otherwise yPath[x_] = -((3 Sqrt[25 - x^2])/5); zPath[x_] := Sin[x] Sin[yPath[x]] comparison[x_] := yPath[x] == (-yPath[x]) ...


1

Try the following shory code: DeleteDuplicatesBy[lst,Floor[#,10^-4]&] Will this help?


1

Following up on Verbeia's comment, it is probably easier to use Which, especially when you get to your Vertex rendering function, which has more nested Ifs. For the present case: Which[#2 === what, "yay", #2 === whoops, "nay"] & @@ {-5, what} returns "yay" or "nay" as desired.



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