This tag is intended for the review and improvement of style for already functioning code. It not meant to change the objective of the code.

learn more… | top users | synonyms

28
votes
1answer
962 views

Fast Spherical Harmonics radiative transfer

This is a rather specific question and I apologize for spamming you with some lengthy code. But it could be interesting for some reader and maybe you can help out, so please bear with me. I am using ...
6
votes
0answers
112 views

Fine tuning compiled code that computes dilogarithm function

As an exercise of writing a good Compile function, I want to do the simple task of coding a routine that outputs the real part of the dilogarithm function ...
5
votes
0answers
90 views

How can I do a two dimensional `Fold`?

I'd like to Fold over higher dimensional objects than lists. Semantically, the format would be something like ...
4
votes
0answers
88 views

Better way to compute triple (or higher order) convolution

I have an identity that I want to verify: $$\sum_{i+j+k\ge ...
3
votes
0answers
195 views

Nonlinear FEM and FindRoot

I'm trying to develop a kind of nonlinear FEM application using mathematica to solve a bvp like the following: $$ \gamma(u') ~u^{iv} + 2 \gamma'(u') u''' u''+ u''^3 = f(x) $$ where $u = ...
1
vote
0answers
40 views

Reducing quantile & color map queries for use with Associations

This set of queries perform basic maps to quantile and then color-map. There's got to be a more compact solution. What are some approaches to reduction? Numeric: ...
1
vote
0answers
102 views

How can I improve the solution of my PDE?

I want to improve the last code to find a better solution for umi. For now I'm using only MaxStepFraction. Also, when I put no ...
1
vote
0answers
102 views

Collision detection algorithm (discrete) with sweep and prune algorithm for periodic boundary conditions

EDIT: Question Updated with solution approach, but solution much slower than original implementation. Any ideas to speed up implementation? In the discussion on collision detection (see here) I asked ...
1
vote
0answers
83 views

Am I simulating correctly my hidden markov chain?

I want to simulate a hidden markov model, in which $y_t|y_{t-1},x_t=i \sim N(\theta_0y_{t-1}+\theta_i,\sigma^2)$, where $y_t$ is the observations or data, and $x_t$ is the state variable of the ...
1
vote
0answers
60 views

Problem with converting recursive code to iterative

I am trying to convert a snippet that uses recursion into one that uses iteration for drawing an L-tree, but my code produces duplicate points. How do I avoid generating them? Recursive version: ...
1
vote
0answers
55 views

Implementing normalization/rescalement from a Tutorial

I'm trying to implement a rescale/normalization as is described in here by mathematical expressions in page 10, and code in the top part of page 16. The notebook is also available here. The objective ...
1
vote
0answers
118 views

How to tweak the following purely numerical code

I am using the following numerical function in my program and I would like to speed it up. ...
0
votes
0answers
60 views

Inverse Superposition

There are 4 tables that, I have written them as bellow: (m, n, s, and r are orthogonal basis. r.r=n.n=m.m=s.s=1, and m.n=n.r=...=0). a's, b's, c's and d's are coefficients and are numeric values. ...
0
votes
0answers
67 views

Matrix iteration failing after second step

I am calculating 11x6 matrix using different logics as in below code. Problem is in Do loop in below code where I have two different criteria to update matrix "fd". I am expecting logic in IF which ...
0
votes
0answers
63 views

Optimising prime number test code

Is it possible to speed-up this code ? Also, It would be great if people could test this algorithm. I only have a Raspberry Pi to test it on, so I can't be certain it's not a strong probable prime ...
0
votes
0answers
59 views

How to eliminate all terms of a variable with square root in an equation?

I did the following thing: take an equation with square root terms, by moving terms and squaring two sides, finally ending up with a polynomial of the specific variable. My algorithm is like this: ...
0
votes
0answers
41 views
0
votes
0answers
56 views

How to Fold (FoldList) this in a more compact (efficient) way?

Example code: x = Table[something[i], {i, 5}] Table[Fold[f1[#1, f2[#2, a], a] &, x[[i]], {c1, c2, c3}], {i, Length[x]}] This above is just an example. I ...
0
votes
0answers
148 views

Code performance problem

Could anyone help me with the attached code? How would you speed up my attached code in some degree? Your comments are highly welcome. ...
0
votes
0answers
70 views

how to generate repeatable Unique streams?

I need to label some data in arbitrarily nested ragged lists, with a stream of unique labels. It's very convenient if the labels are consecutive integers, starting at 0 or 1, and if I can produce the ...