Tag Info

24

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.... 7 Alternative solutions: You could use ImageApply on images: ImageApply[Max, {i1, i2}]; // RepeatedTiming {0.0239, Null} Or MapThread on lists: Image[MapThread[Max, ImageData /@ {i1, i2}, 2]]; // RepeatedTiming {0.0231, Null} And, somewhat surprisingly this uses 2 multiplications and 3 additions per pixel: ( {d1, d2} = ImageData /@ {i1, i2}... 6 You can add a new variable in Reduce do get your multiplication, just like this In[13]:= Reduce[ ans == x y && x*y > 50 && x*y < 100 && x < 100 && x > 1 && y > 1 && y < 50, ans, {x, y}, Integers] Out[13]= ans == 51 || ans == 52 || ans == 54 || ans == 55 || ans == 56 || ans == 57 || ans ... 5 Sequential With From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows: With[{a = 0}, {a = a + 1}, {a = a + 1}, a] 2 5 It's simpler than that, since you can use the built-in image processing function ImageApply: img1 = Import["http://i.stack.imgur.com/bBsDH.png"]; img2 = Import["http://i.stack.imgur.com/O9Vm6.png"]; ImageApply[Max, {img1, img2}] 4 Clear["*"] clears every symbol found on$ContextPath which is not Protected. So many System symbols too... Moreover, unless you want to double clear SystemAll, Clear["*", All] is made up syntax. What you probably want is Clear["Global*"] or ClearAll["Global*"] Weren't you warned by:

4

Two possible ways: listfun = {Sin, Cos, Tan}; Through[listfun[Pi]] (* {0, -1, 0} *) #[Pi] & /@ listfun (* {0, -1, 0} *)

4

The issue was due to a simple, but unobvious syntax mistake. The intended behavior is given by FoldList[cpdz[#1, 2, #2, 0.01, 2, 720] &, 1569.3 , #] & /@ SetofLists

3

Here is a block-based modification of the first method in my answer to the earlier question: fnBlock[x1_, x2_, primes_List] := Fold[ # ~Complement~ Range[x1 + #2 - Mod[x1, #2, 1], x2, #2] &, Range[x1, x2], primes ] fnMem[x_Integer, n_Integer, block_: 1*^6] := With[{pr = Prime @ Range @ n}, Join @@ Table[ fnBlock[1 + i ...

3

Transpose only takes a list of lists as it 1st argument. Transpose[{{a, b, c}, {d, e, f}}] {{a, d}, {b, e}, {c, f}} Transpose[{{a, b, c}, f[{d, e, f}]}] Transpose[{{a, b, c}, f[{d, e, f}]}] NumberForm is just another head like f. Transpose[{{a, b, c}, NumberForm[{d, e, f}, {∞, 10}]}] // FullForm Transpose[ List[List[a, b, c], NumberForm[...

3

Your code looks reasonable to me. If I were doing this, I would manually Protect those symbols on the off chance that for some reason I accidentally assigned them values (though this is not necessary for them to work), assign them ::usage messages so they register correctly into the system (and therefore display in black instead of blue, and use === (i.e. ...

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

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

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

Suppose all your digtal is non-negtive,I give a undocumental function for this lst1 = {{1, 2}, {3, 4}}; lst2 = {{5, 1}, {7, 2}}; InternalMaxAbs[lst1, lst2] {{5,2},{7,4}}

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

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

2

Here is code that makes the plot of 1st ReandIm of the function without messages. Clear[f, "G*", ϕ] f[x_?NumberQ] := Exp[-(x - 5)^2] G1[b_?NumberQ, σ_, λ_] := 0 G2[b_?NumberQ, σ_, λ_] := (1/π) Sqrt[ b/σ] EllipticK[ Abs[(λ^2 - 4 (σ - b)^2)/(16 σ*b)]]; G3[b_?NumberQ, σ_, λ_] := (4/π)*((b)/(Sqrt[\ λ^2 - 4 (σ - b)^2])) EllipticK[ Abs[(16 σ*b)/(λ^2 ...

2

EDIT Using to rules will be better: x y/.{ToRules@Reduce[x*y > 50 && x*y < 100 && x < 100 && x > 1 && y > 1 && y < 50, {x, y}, Integers]} @Michael thanks! in your situation, the result will be in the form x==2&&y==26||x==2&&y==27...... so we can use replacement rules to make it ...

2

Your code has syntax errors. It should be Strain[neuaxis_, y_] := Module[{b = 0.003, a}, a = -b/neuaxis; a*y + b] Stress[neuaxis_, y_] := Module[{temp, Es = 200*10^3, fsy = 500}, temp = Strain[neuaxis, y]*Es; If[temp > fsy, fsy, If[temp < -fsy, -fsy, temp]]] but I would write With[{b = 0.003}, Strain[neuaxis_, y_] := b (1 - y/neuaxis)] ...

2

Whenever the current computation depends upon the result of the previous step, think FoldList. FoldList is a fast and efficient function to use for those cases. Let's look at this for three steps where the inputs are symbolic (tip: don't use upper case symbols, you may end up clashing with system symbols). vt[ea_, v0_, cm_, b_] := ea + (v0 - cm)*b ea = {...

1

RecurrenceTable[{vt[n + 1] == EA + (vt[n] - Cm)*B, vt[1] == 3500}, vt, {n, 1, 10}]

1

Have a look at, Music Package MUSIC PACKAGE TUTORIAL Sound and Sonification Signal Processing Sound The Representation of Sound << Music` Play[Sin[2 \[Pi] Aflat4 t] + Sin[2 \[Pi] Eflat5 t], {t, 0, 0.2}] And a verry nice external Site The Physics Hypertextbook N.B.: The distinction between music and noise is mathematical form. Music is ordered ...

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

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

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