Tag Info

New answers tagged

2

Isn't this is a problem of mathematics more than programming? Under the stated conditions, by permutation symmetry of the indexes of $v$ all entries of $v$ should be the same (up to absolute value, because in the problem statement all elements are squared). Thus one answer is $v$ is an array of $c$ entries each of which is $n/c$. This solution is ...


1

You're like 99% of the way there. You just need to tell Mathematica that z is a vector by feeding it the components: With[{z = Array[v, 3]}, Minimize[{Total[z^4]/Total[z^2]^2, Total[z] == n}, z]] For dimensions 1 and 2 the answers are as expected. For 3 (the code above) Minimize outputs a bunch of ugly Roots. So although there is a symbolic solution, ...


1

From the documentation, StepMonitor is an option for iterative numerical computation functions that gives an expression to evaluate whenever a step is taken by the numerical method used. Meanwhile, EvaluationMonitor is an option for various numerical computation and plotting functions that gives an expression to evaluate whenever functions ...


1

Version 10 has a new function FindPeaks that can be used here: f[x_] := x Sin[x]; list = Range[1, 10, 0.1]; FindPeaks[f /@ list] This returns the location (in the list) and value of the local maxes. Another new function that's related is MaxDetect, which returns a vector of zeros (at all the non-max locations) and ones (at all the max locations). ...


4

For an exact solution: f[k_, x_] = -k^x + x^2; soln = Reduce[{f[k, x] == 0, D[f[k, x], x] == 0, x > 0}, {k, x}, Reals] // ToRules {k -> E^(2/E), x -> E} f[k, x] /. soln 0 k /. soln // N[#, 17] & 2.0870652286345330 Plot[f[k /. soln, x], {x, 2, 3}]


3

Having just one root requires eq1 = -k^x + x^2 == 0; eq2 = D[-k^x + x^2, x] == 0 (* 2*x - k^x*Log[k] *) FindRoot can solve for x and k simultaneously. FindRoot[{eq1, eq2}, {{x, 2.5}, {k, 2}}] (* {x -> 2.71828, k -> 2.08707} *) Plot[(-k^x + x^2) /. %[[2]], {x, 2, 3}]


1

Try data3 = Flatten[Table[{p[[i]], q[[j]]}, {i, 1, dimp}, {j, 1, dimq}], 1] Export["data3.dat", data3, "Table"];


1

Here is one approach. I have not tested it so there might be unforseen hitches. I'll refer to your matrices as matrixA, matrixB1, and matrixB2 respectively. Define minEig[mat1:{{_Real..}..},mat2:{{_Real..}..}] := Min[Eigenvalues[mat1-mat2]] newB = Array[b, Dimensions[a]]; obj = Trace[matrixA.newB]; FindMinimum[{obj, minEig[newB,matrixB1]>=0, ...


2

As suggested by @mgamer you do need memoizing. If all you care about is the flight length then you do not need the actual function, just recursively define collatzLength[1] = 0; collatzLength[n_Integer] := collatzLength[n] = 1 + If[EvenQ[n], collatzLength[n/2], collatzLength[3*n + 1]] Timing[Max[Map[collatzLength, Range[1, 1000000]]]] returns ...


3

Defining the "Collatz"-Function like you did is straight-forward, but in the sense of Mathematica not optimal. When computing the length of a Collatz-Sequence a lot of duplicate calculations are done. So defining: collatz[n_] := collatz[n] = If[EvenQ[n], n/2, 3*n + 1] prevents Mathematica from doing duplicate evaluation. This is more efficient than ...


4

By taking advantage of the trigonometric identity, 2 Sin[m π χ] Sin[p π χ] == Cos[(m - p) π χ] - Cos[(m + p) π χ] the number of integrals to be performed can be reduced from Nmax^2 to 2*Nmax+1, as savings of nearly a factor of 40 for Nmax = 80. Nmax = 80; dct = Table[Integrate[Cos[i π χ] V[χ], {χ, 0, 1}], {i, 0, 2 Nmax}]; Hmp = Table[(p^2 π^2)/2 ...


4

You have to specify the variables in the FindMinimum command: z[x_, y_] := x + I*y; f[x_, y_] := Abs[z[x, y] - (1 + I)^2]; FindMinimum[f[x,y], {x, y}] Out[1]={1.28247*10^-8, {x -> -3.00876*10^-9, y -> 2.}}


3

data = SemanticImportString[ "0.3858 0.4687 1 65.5261 0.4871 0.611 -1 65.5261 0.9218 0.4103 -1 0 0.7382 0.8936 -1 0 0.1763 0.0579 1 0 0.4057 0.3529 1 ...


1

Calculating the fit manually (because sometimes it's nice to see the steps). Not sure if these are the specific errors (residuals) you want. data = {{0.3, 5.9}, {0.5, 5.1}, {0.6, 6.8}, {0.7, 6.3}, {0.9, 8.1}}; MapIndexed[(X[First@#2] = #1) &, First /@ data]; MapIndexed[(Y[First@#2] = #1) &, Last /@ data]; {n = Length[data], ΣX = Sum[X[i], {i, ...


6

To shuffle a list simply apply RandomSample: RandomSample @ Range[9] {3, 7, 1, 8, 4, 9, 6, 2, 5} See Shuffling a list in Mathematica for other ideas.


3

how I can get a completely unordered list lst = {"DSC00025.JPG", "DSC00026.JPG", "DSC00027.JPG", "DSC00028.JPG", "DSC00029.JPG", "DSCI6714.JPG", "DSCI6715.JPG", "DSCI6716.JPG", "DSCI6717.JPG", "DSCI6718.JPG", "DSCI6719.JPG", "DSCI6720.JPG", "DSCI6721.JPG", "DSCI6722.JPG", "DSCI6723.JPG", "DSCI6724.JPG", ...


5

This interesting behavior seems to be a characteristic of the interior point method, which is the only one available in FindMinimum that is applicable to constrained problems. That it is due to the method and not the existence of constraints can be seen by removing the constraints and specifying the method explicitly. Ramping the precision from ...


2

Update In a comment Oleksandr pointed out that the number of iterations may be having an effect. This is evident from running the following code: max = 10; qp = Table[Unique[{q, p}], {max}]; qpFlat = Flatten[qp]; eqn = totalenergy[qp, max]; ceqn = Compile[Evaluate[{#, _Real} & /@ qpFlat], Evaluate[eqn], "RuntimeOptions" -> ...



Top 50 recent answers are included