Tag Info

New answers tagged

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


1

The reason is that you have an inefficient inner loop when you use myBBBlik. Every time you call myBBBlik, it takes a certain amount of time to calculate the result (on my computer, about 1/2 second of mucking around because your likelhood function is a bit complex). But myBBBlik2 creates an algebraic expression once (?or twice?) and can substitute the ...


0

Yes, for one, you can put all the accessors into one [[..]]: Maximize[pi[p[q1, q2], q2], q2][[2, 1, 2]] The second way is to use the rule -> in the last part the result directly q2 /. Last@Maximize[pi[p[q1, q2], q2], q2] The result from functions like Maximize, NMaximize, Minimize or even Solve might look strange for a beginner, but rules and ...


9

As was pointed out above, this is a good summary of Mathematica's constrained optimization methods. Read through this if you want to know a lot more. A quick answer is below: The answer to your question is strongly dependent on the function you want to maximize. Convex functions can be maximized quite easily, with the error controlled by the PrecisionGoal ...


18

maybe this will provide a little insight: first look at the evaluation points used by ContourPlot: f[x_?NumericQ, y_?NumericQ] := (Sow[{x, y}]; Sin[3.2 x]*Sin[1.3*y] - 2.1*Sin[1.3*x]*Sin[3.2*y]); {plot, dat} = Reap[ContourPlot[f[x, y] == 0, {x, 0, 2}, {y, 0, 2}, PlotPoints -> 50, ContourStyle -> Red]]; Row[{ ...


0

Here is an approach that is much faster, but with potentially some loss of accuracy. Do away with NIntegrate and eval the function at preselected points in the region: nsamp = 200; pts = Select[ Table[{RandomReal[{0, gam1 + Re[gam2]}], RandomReal[{0, Im[gam2]}]}, {nsamp}] , # \[Element] \[ScriptCapitalR] & ]; ...


0

It does give a result if you consider four different cases for the signs of a and b: f[{g_, h_}, a_, b_] := g[a, 0] && h[b, 0] Minimize[{(e - x)^2 + (n - y)^2, a e + b n == c && #}, {e, n}, Reals] & /@ (f[#, a, b] & /@ Tuples[{Greater, Less}, 2]) The result is too large to ...


1

Here is another alternative for how to speed up the plotting if you want to retain all the functionality and options of ContourPlot: use ParallelTable: f[a_?NumericQ, b_?NumericQ] := NIntegrate[a*x + b, {x, 0, 1}]; Timing[Show[ ParallelTable[ ContourPlot[f[a, b], {a, 0, 10}, {b, 0, 10}, Contours -> {i}, ContourShading -> None, ...


4

Update: Using the memoization trick suggested by @george2079 in the comments combined with MeshFunctions we get the same picture in 0.015625 seconds: fa[a_?NumericQ, b_?NumericQ] := fa[a, b] = NIntegrate[a*x + b, {x, 0, 1}]; First@Timing[ContourPlot[fa[a, b], {a, 0, 10}, {b, 0, 10}, Contours -> {}, ContourShading -> None, MeshFunctions -> ...


7

I am playing with some Compressed Sensing (think single pixel camera) applications and would like to have a Mathematica equivalent of a Matlab package call Convex Optimization (CVX). [...] very slow compared to the Matlab code written by a colleague. I don’t want to give him the pleasure of thinking Matlab is superior CVX is the result of years of ...


2

FindFit does perform symbolic differentiation by default. It has the option to use finite differences instead via the option Gradient -> "FiniteDifference". There is worked example in the documentation here.


1

saving and reopening my notebook got rid of them


2

Yes it does. You can see this by using a function that prints the argument passed to the function evaluated in the FindFit procedure. For example you could use this little setup: data = Table[{x, 2.5*Exp[x]}, {x, 0, 1, 0.1}]; f[a_, x_] := Block[{}, Print[x]; a*Exp[x]] FindFit[data, f[a, x], {a}, x] What you will notice, when you execute the code, is that ...



Top 50 recent answers are included