New answers tagged

4

If has attribute HoldRest, which you can clear, but I don't recommend that. I think the right solution is to replace a[HoldedArgument] by a[#] &[ToDoBeforeHold], i.e. q[y_] = y; For[i = 1, i <= 4, i++, q[y_] = q[If[1 - i <= x <= 2 + i, #, #2] &[i, y]]]; f[x_] = q[If[7 <= x <= 6, 10 x, x]]; f[x]


5

You may use Piecewise. For your For loop function g[x_] = Piecewise[{#, 1 - # <= x <= 2 + #} & /@ Range[4]] Plot[g[x], {x, -3, 6}] For your example function f[x_] = Piecewise[{ {x , 0 <= x <= 1 - 1/5}, {-x + 2 , 1 + 1/5 <= x <= 2}, {1 - 1/5 , True} }] Plot[f[x], {x, 0, 2}] Hope this helps.


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


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


0

Maybe something like this would be useful. L = 1; u[x_] := Subscript[u, 0][x] + p*Subscript[u, 1][x] Distribute[ Integrate[ Distribute[(1/Gamma[L-α]) (x-τ)^(L-α-1)*D[u[τ],{τ,L}]], {τ, 0, x} ]]


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


6

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


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


0

Your If contains C > 0, so when you try a3[2, list1, list2, list3], you are trying to compare a List with an Integer. That would not be evaluated. Try this: a3[m_, C_, St_, Stt_] := If[AllTrue[Flatten[C], Positive], (m*C)/St*Stt, 0]


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


4

Clear["*"] clears every symbol found on $ContextPath which is not Protected. So many System` symbols too... Moreover, unless you want to double clear System`All, Clear["*", All] is made up syntax. What you probably want is Clear["Global`*"] or ClearAll["Global`*"] Weren't you warned by:


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


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


4

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


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


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


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}}; Internal`MaxAbs[lst1, lst2] {{5,2},{7,4}}


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


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


1

The proposed snippets are working on 10.0 for Mac OS X x86 (64-bit) (December 4, 2014) ClearAll["Global`*"] Profit = (8 c^2 - 16 c*s - 10 c - 4 s - 3)/(32 s + 16) $\frac{8 c^2-16 c s-10 c-4 s-3}{32 s+16}$ Plot3D[Profit, {c, -0.286031, 0.286031}, {s, -0.347656, 0.347656}] Plot3D[8 c^2 - 16 c s - 10 c - 4 s - (3 s)/32 + 16, {c, 0, 2}, {s, 0, 1}] ...


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


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


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



Top 50 recent answers are included