Linked Questions

1
vote
0answers
91 views

Understanding Mathematica: How to write fast code? [duplicate]

I'm relatively new to Mathematica but have done a few projects using it so I'm quite comfortable with the syntax and the basic functions available. Since I've had programming experience in the past I ...
0
votes
0answers
65 views

Automatic Cuda/CPU code; Fast programme run [duplicate]

I have developed my thesis codes by means of Mathematica software in a .nb file format. Despite using the available Parallel code capabilities and doing all the numerical integrations by means of ...
532
votes
19answers
133k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
129
votes
8answers
7k views

Can one identify the design patterns of Mathematica?

... or are they unnecessary in such a high-level language? I've been thinking about programming style, coding standards and the like quite a bit lately, the result of my current work on a mixed .Net/...
34
votes
9answers
3k views

How to select minimal subsets?

I am a newbie, so please point me in the right direction if you feel this question has been answered somewhere else before. Here goes: Suppose I have a list like this: ...
52
votes
4answers
4k views

How can I implement dynamic programming for a function with more than one argument?

Dynamic programming is a technique for avoiding the repeated computation of the same values in a recursive program. Each value computed is immediately stored. If the value is needed again, it is not ...
88
votes
2answers
5k views

Profiling from Mathematica

I've always wished I could do some profiling like you get in Wolfram Workbench, but directly from Mathematica, without using or having Workbench. If it is possible, how can I do it?
3
votes
5answers
2k views

Find the slope between adjacent points in a list

I have a list of two dimensional points that are ordered by their x-coordinate. I would like to calculate the slope between all adjacent points. I'm familiar with the use of pure functions in Sort ...
14
votes
2answers
1k views

Finite difference method not converging to correct steady state or conserving area?

I am working with the following PDE, which is an advection-diffusion type equation. It describes the movement of a fluid-fluid interface inside an annulus of inner radius $R_1$ and outer $R_2$ under ...
9
votes
2answers
650 views

Optimizing Mathematica Code

I have implemented the whole Baum-Welch Algorithm for training Hidden Markov Models as described in Rabiner's paper Here is my code that calculates the Forward Probabilities` ...
4
votes
4answers
352 views

Combination of lists elementwise

I have two lists: x = Range[1, 10, 1] y = Range[2, 10, 2] How can I produce a list consisting of the following elements (first element is the x value, second ...
5
votes
7answers
310 views

How to use AppendTo in a While loop? [closed]

I am trying to code a while loop that uses AppendTo to append the loop variable to an empty list. ...
4
votes
4answers
387 views

Delete sublists exceeding certain length

Given a list like list={{1},{2,3},{3,4,6},{6,7,8,5}}; I would like to very efficiently delete all sublists that are longer than a specific length, i.e.: ...
8
votes
2answers
796 views

Dynamic plot with synchronization of real time

I want to do a dynamic plot with synchronization of real time, that is, I have a function, f[t], that is a function of time (seconds), so I want to see the curve changing not so fast or not so slow, ...
67
votes
1answer
2k views

Is this the most effective and efficient programming style for prototyping (a ray tracer) in Mathematica?

I am trying out Mathematica as a prototyping tool. As an initial exercise I have put together a brute force ray tracer, with a view to using Mathematica's built in probability distribution functions ...
11
votes
2answers
1k views

Dynamic Programming with delayed evaluation

By using dynamical programming, we can save intermediate steps for recursive relations, as in f[n_]:= f[n] = f[n-1] + f[n-2] However, this only stores ...
8
votes
2answers
583 views

Why won't this compiled function be inlined?

I've been trying to use Compile to get some code to execute more quickly, because I will need to call it millions of times. I've been using the ...
6
votes
2answers
161 views

Achieve performance that is competitive with numpy [duplicate]

What are the best practices to ameliorate time performance of Mathematica? As a practical example how we can decrease timing below? ...
5
votes
2answers
252 views

ParallelMemberQ

I tried to make a parallel version of MemberQ for use with a large list, but failed miserably in terms of performance. I used Partition to subdivide the list and ParallelMap to perform the MemberQ ...
2
votes
6answers
480 views

Color points in list plot based on whether they satisfy an equation

I wanted to create a set of points (a,b) such that a, b are both integers between -6 and 6. Then I want to color all points (a,b) that satisfy $|a-b|\ge2$ red, and all the remaining points blue. I ...
4
votes
2answers
310 views

EventHandler and Refresh rate

Based on the example of the Documentation of MousePosition, Properties and Relations, here is my test code using "MouseDragged" instead of "MouseClicked": ...
5
votes
2answers
226 views

Mathematica taking forever to compute

I want to simulate the fresnel diffraction through circular aperture.But mathematica is taking forever to calculate.Here is my code. ...
1
vote
3answers
302 views

professionalize/optimize my code that calls a function

I have the following construction, which defines a function that I subsequently call in a loop multiple times. I use this very often, but I have never looked into if there is a more professional way ...
4
votes
1answer
354 views

Sample of the random times at which the random walk crosses the boundary

I defined a security boundary for a random walk: ...
2
votes
3answers
323 views

Random Geometric Graphs, but fast

I am optimising the random geometric graph generation ideas in this post. I need to generate a large number of random geometric graphs with probabilistic connectivity (soft random geometric graphs), ...
2
votes
1answer
559 views

Understanding execution time in nested loops

I have the following simple code ...
5
votes
2answers
149 views

A box structure with a depth exceeding the maximum allowed depth was encountered

I am trying to perform the task in Mark McClure's article Parametric L-Systems and borderline fractals. I have copied his opening code on the first three pages: ...
4
votes
2answers
606 views

Collatz Tool Box — any speed ups possible?

I have created a tool box for experimenting with the Collatz conjecture. Info here: Wolfram MathWorld and here: Wikipedia The patterns I have found allow us to make the conjecture jump through some ...
3
votes
1answer
689 views

How to estimate the running time of a programme on mathematica [closed]

I am solving a system of 6 linear equations containing six unknowns using mathematica. It is taking too much time and still running after 3 hours. can I estimate the approximate running time? Is there ...
4
votes
0answers
557 views

Understanding performance: graph connected components

I need to analyze directed graphs with 10M edges, 1M vertices, and 300K strongly connected components, so that the largest one contains 400K vertices. I read some explanations of Leonid Shifrin here, ...
1
vote
1answer
246 views

How should I go about writing more functional and list based code? [duplicate]

I've heard that Mathematica is usually faster when the code is list-based and/or uses a functional paradigm. I'm still working on getting the hang of this; there are a lot of ...
0
votes
1answer
95 views

How can I improve performance of my simulation code?

1) Generate nNsamples from beta distribution (a, b) and the parameter of wighted c ...
2
votes
2answers
80 views

`Solve` Performance Tuning

I'm facing a Problem in Mathematica, where I have to solve a large number of equations generated by an AppendTo. ...
3
votes
1answer
102 views

Access to the temporary solution in NDSolve with StepMonitor

I want to step-monitor at each time step of a spatio-temporal NDSolve (using the finite element method) the maximum bending of the function sampled over the curent mesh. For this I first need access ...
2
votes
1answer
95 views

Code optimizations with functions inside Module

I wrote a small code by using functions inside Module: ...
0
votes
0answers
247 views

Using Table[ ] vs using Do[Append [ ] ] [duplicate]

Is it generally better/faster to use the Table function over using Do[Append []]? For example, I have this piece of code: <...
0
votes
0answers
112 views

Performance tuning with memoisation, compilation and vectorization - further possibilities?

In order to tune the performance of noticeably slow code of mine, I had a look at many different excellent posts on this topic here on M.SE, e.g. here to name the most interesting one. Now I ask ...
1
vote
1answer
83 views

Compilation without MainEvaluate

I'm trying to avoid MainEvaluate in CompiledFunction. I've tried below but I couldn't get rid of it. I'd appreciate any help!! Here f1 and f2 will be rank 1 list with real type. ...
3
votes
0answers
92 views

How to make reading from long lists faster?

Background I am using Mathematica to solve a traveling-salesman-like problem. I implemented two different algorithms that are able to solve this type of problem and both algorithms yield the same ...
1
vote
0answers
91 views

Mathematica using all available cores, but not speeding up calculation as much as expected

This is a follow-up question to my previously posted question on how to get Mathematica to use all available cores to do a parallel calculation. I resolved this by rewriting the code in terms of a <...
0
votes
0answers
84 views

averaging over large number of random realizations

I want to run following for few hundreds of a random variable set. This calculates: generate normal random variable find gain with squaring calculate performance metric find ...
3
votes
0answers
80 views

Where can I find detailed information about the SystemOptions?

I'm looking to optimize my Mathematica script, and I'm willing to go spelunking with low-level system options. The problem is that I've been looking in the Mathematica documentation, but there doesn'...