Skip to main content

Questions tagged [coding-style]

Questions on how to write code in a better or different style, using Mathematica's capabilities for coding in multiple styles.

Filter by
Sorted by
Tagged with
2 votes
1 answer
126 views

NDSolve: how to solve "ndnum error"

I have a problem of finding the shape of a current. please see the details here NDSolve does not accept the boundary condition I wrote a code but it gives the "ndnum" error. I tested the ...
AWer's user avatar
  • 35
0 votes
0 answers
58 views

NDSolve does not accept the boundary condition

I am new at Mathematica and trying to solve a nonlinear PDE with the help of NDSolve. H, the height of the current is a function of x and t. Based on the context I know the current has a parabolic ...
AWer's user avatar
  • 35
1 vote
1 answer
79 views

Customising the editor: (real) monospace font and dark theme (and more)

I don't know how to make the code editor in Mathematica present the code in a real 'monospace' font, with a dark, customisable theme (syntax highlighting and so on). This is something that keeps me ...
Vicent's user avatar
  • 1,101
0 votes
1 answer
70 views

How to make code for boundary value problem?

I am trying to make graphs given by using this code but I failed. Please correct this code. ...
riaz iram's user avatar
1 vote
3 answers
84 views

Labeling point coordinates in path graph using VertexLabels

Question: How do we label point coordinates in Pathgraph using VertexLabels. Suppose we have a list of points ...
Arbuja's user avatar
  • 71
1 vote
3 answers
290 views

Creating an interactive plot that zooms into the function

Suppose we want an interactive plot for the code: ...
Arbuja's user avatar
  • 71
7 votes
4 answers
740 views

How to elegantly implement this one useful object-oriented feature in Mathematica?

I wrote some Mathematica code that defines a function I want to use repeatedly (f) inside another function (finit) that pre-...
jjoIV's user avatar
  • 173
0 votes
0 answers
130 views

Codewars and Mathematica

I looked up the Wolfram Language on Codewars as the site is great to improve coding. WL is not among the listed languages (I checked the beta versions as well). I assume this is because the language ...
ExpressionCoder's user avatar
9 votes
1 answer
139 views

Best practices or hidden drawbacks to define multiple-argument functions

I was wondering if there were any important differences or stylistic considerations for deciding between different ways to define functions of multiple variables, e.g. ...
Diffycue's user avatar
  • 1,844
2 votes
2 answers
348 views

Would it be poor advice to assign roman numerals as top variables?

For example like so. x = 10; xi = 11; xv = 15; Is there an automated way to spit these numbers out maybe 1-1000.
William's user avatar
  • 7,605
8 votes
6 answers
705 views

Smart way to remove rules from lists, leaving just values, specifically from FindMinimum output

I would like to know if there is a direct way to remove the rules from a list of rules. I know that, simply, this can be done with: ...
Joshua Salazar's user avatar
7 votes
4 answers
431 views

How can I efficiently define functions with different names but doing the same stuff?

Recently I have met with with this interesting question:How can I efficiently define functions with different names but doing the same stuff? Somebody may want to ask me why I want to do things like ...
AlbertLew's user avatar
  • 483
1 vote
2 answers
115 views

How to organise definitions that contain named parameters?

I have lots of definitions of (usually numeric) quantities that depend on parameters; they're mostly matrices (in the actual code, there are many more definitions): ...
Deniz's user avatar
  • 235
-2 votes
1 answer
96 views

How to find the Mathematica command for the function $a_k?$ [closed]

I am trying to find the $n$-th derivative of $\csc(m\pi)$, so I took few cases: for simplicity let $x=\cot(m\pi)$ and $y=\csc(m\pi)$, $$\frac{d^0}{dm^0}\csc(m\pi)=\pi^0(\color{red}{1}x^0y^1)$$ $$\frac{...
Ali Shadhar's user avatar
-1 votes
1 answer
75 views

what is the Mathematica command for the Euler numbers $E_k?$ [closed]

We know that the Euler numbers $(E_r)$ has many integral and series representations but I am wondering if there is a simpler Mathematica command.
Ali Shadhar's user avatar
3 votes
4 answers
271 views

Fall through multiple statements in Switch[]

Is there a nice way in Mathematica to express the equivalent of Switch where statements (not cases) fall through? Here is a toy example in C: ...
Bob Werner's user avatar
2 votes
0 answers
169 views

Coding style/formatting rules used by Wolfram developers [closed]

I wondered whether there is a known formatting guide that Wolfram employees (have to) use when writing Mathematica code? As stated in Mathematica style guide? there are many different formatting ...
Gert's user avatar
  • 1,530
0 votes
0 answers
50 views

Finding the limit of the average of a sequence?

...
Arbuja's user avatar
  • 71
5 votes
0 answers
207 views

What do “Analyze Notebook" and "Analyze Cells" Do?

What does "Analyze Notebook" and "Analyze Cells" do? They seem to, at least, point out some coding errors that are already highlighted in a notebook. Do they do anything else? Is ...
Just Some Old Man's user avatar
0 votes
0 answers
165 views

Determining whether a matrix is in Jordan canonical form

At first, I was surprised that Mathematica doesn't have a built-in function for this, e.g. JordanMatrixQ. Anyway, we all know that a Jordan matrix is consisted of ...
polfosol's user avatar
  • 952
0 votes
1 answer
43 views

Loop for different values

I have the following: ClearAll["Global`*"] n= 3; T = Transpose[Table[{t^i}, {i, 0, n}]]; B = DiagonalMatrix[Range[n], 1, n + 1]; Print[ T, B] I want ...
user62716's user avatar
  • 731
3 votes
0 answers
255 views

Robust PCA (better Mathematica style)

I've parsed (almost verbatim) Python RPCA implementation to WM. Can it be rewritten using a better WM style? In particular, I'm not happy with ...
I.M.'s user avatar
  • 2,986
2 votes
1 answer
187 views

An alternative command to compute a logarithmic integral [closed]

I am trying to see if Mathematica can calculate: $$\int_0^1\frac{\ln(x)\ln(1-x)\ln(1+x)}{x}dx,$$ which has a closed form found here. So I tried ...
Ali Shadhar's user avatar
0 votes
1 answer
494 views

How to remove complex infinity

I have an equation for the effective potential for a neutral particle (non-spinning), i.e. VeffNonSPIN[r_, θ_] := (1 - 2/r)*(1 + LL^2/(r^2 Sin[θ]^2)); If I take ...
MMS's user avatar
  • 87
6 votes
1 answer
190 views

Mimicking named arguments, a good idea? (programming style)

With respect to code readability I like the possibility to use keyword (named) arguments. I would like to have this under Mathematica, but AFAIK there is no native support for that. By example, to ...
Picaud Vincent's user avatar
0 votes
1 answer
61 views

How can I add the tangent line from Fun 2 to Fun 3 to this function?

Question: I need to move the point Fun1 to 10 positions in the interval [-3,0), and have the drawing updated each time (including the tangent and intersection points). I don't know how to add Fun2-...
Qy Ln's user avatar
  • 69
2 votes
1 answer
136 views

Question about finding the area

Here is a link to my previous question Question about plotting a curve and tangent lines I want to know how can the area be found between the curve and tangent line for between Point Fun1 and Fun2....
Qy Ln's user avatar
  • 69
4 votes
3 answers
545 views

Question about plotting a curve and tangent lines

This is a Mathematica question. I have a function $y=x^3$. “Fun1” is any point on the curve. At the point Fun1, draw a tangent line at that point to the curve. At another point where the curve and the ...
Qy Ln's user avatar
  • 69
0 votes
1 answer
68 views

Find the area which is between two curves using Nintegrate

...
Aran's user avatar
  • 373
0 votes
1 answer
70 views

Question about finding tangents on mathematica?

How can I find the tangent at the point $(2,8)$ to the curve $y=x^2+4$ on Mathematica? How can I show the tangent of the curve at the point and I need to mark the point where they meet with the word &...
Aran's user avatar
  • 373
1 vote
0 answers
132 views

The danger of pattern matching?

I'm reading the book Mathematica® programming: an advanced introduction by Leonid Shifrin and there is a very nice evaluation. Here is: This, plus a large number of quite generic and efficient ...
Nam Nguyen's user avatar
  • 1,761
4 votes
0 answers
148 views

What is the best coding style for performance?

The problem of Mathematica is there are too many ways to perform one task. That leads to confusion for new users because the performances of these methods are so different. I'm learning the best ...
Nam Nguyen's user avatar
  • 1,761
5 votes
2 answers
154 views

Modify each element depending on previous elements

I'm looking to see if there's a more idiomatic/concise/neat solution than what I have for this. I have a list of boxes with heights and I want to stack them; that is, add to each box the distance to ...
Matt Murphy's user avatar
1 vote
2 answers
67 views

Need help with making code work on Mathematica

...
Aran's user avatar
  • 373
2 votes
0 answers
49 views

How to calculate how many points in function f are greater than the average of functions g and k?

Consider 3 functions f, g and k Suppose we want to know for 3. functions from P={(x, y )|x=-1,-0.9,-0.8,-0.7....,1 and y=-1,-0.9,-0.8,-0.7....1 this is what i have so far ...
Aran's user avatar
  • 373
4 votes
1 answer
180 views

What are some debugging helpers or tips/tricks in your Mathematica toolbag?

I am a novice so imagine my confusion with Mathematica's very poor error and trace messages. Debugging should be an easy thing to do even for beginning programmers but not with Mathematica. What are ...
Jules Manson's user avatar
  • 2,467
2 votes
1 answer
113 views

Write repeated expressions within a rule more simply

Is it possible to shorten the length of a (delayed) rule (i.e. lhs :> rhs) when there are expressions which repeat several times? Those expressions involve ...
abcd's user avatar
  • 483
6 votes
0 answers
89 views

In over my head in trying to create a debugger

Apologies for a less than ideal question, but if I could have asked a good question the answer would probably have been revealed in the process... In answer to this question @LeonidShifrin gave some -...
Julian Moore's user avatar
  • 2,560
7 votes
1 answer
150 views

Quick way to preview and tweak styles?

I find the old stylesheet UI clunky and hard to use: FrontEndExecute @ FrontEndToken @ "EditStyleDefinitions" There's also the clunky style previewer as well: ...
M.R.'s user avatar
  • 31.5k
2 votes
1 answer
86 views

BarChart simultaneous axes label and numerical label

So I want to be able to put axes labels simultaneously as the numerical labels. I can achieve that with the following, but is there a better/cleaner way? I can't use callout, because I am using ...
ions me's user avatar
  • 991
5 votes
1 answer
140 views

Best Practice: spending transactions to expense list

So lets say I have a list of spending transactions tlist = {{john,23},{bob,2},{john,7}...} and I want to have a list of the total expenses per person. I can do ...
ions me's user avatar
  • 991
1 vote
1 answer
256 views

Correct use of Reap/Sow to optimize the code

I am trying to compare two functions on the end points of an interval. For instance, $f_1(t)=t^3$ and $f_2(t)=t^4$. From my code below I check whether $f_1(t)\leq f_2(t)$ when $t=50$ on $[50, 51]$ ...
primefinder's user avatar
4 votes
1 answer
181 views

Project and notebook design

I have been using Mathematica now for a little over a year...this started off in maybe a modern 'classic' way of having to solve symbolic mathematics and related plus the want to learn a CAS (and more)...
DrMrstheMonarch's user avatar
9 votes
2 answers
393 views

Using vtx[] instead of vtx

There're two ways to generate a random tree as 1 and 2 below. Both work fine here. So what's the reason to use vtx[] instead of ...
emnha's user avatar
  • 2,111
0 votes
0 answers
35 views

Why is my code for density using Folner Sequences giving incorrect values? [duplicate]

I am creating a code that calculates or approximates $$D(S\cap[a,b])=\lim_{n\to\infty}\frac{\left|S\cap{F_n\cap[a,b]}\right|}{\left|F_n\cap[a,b]\right|}$$ where $D$ is the density of $S\cap[a,b]$ (...
Arbuja's user avatar
  • 71
4 votes
1 answer
103 views

Why is my version of Euler's Method not working?

I am creating Euler's method for $\frac{dw}{dt}=(3-w)(w+1)$ for $\Delta t=0.5$ from $0\le t \le 3$. I tried the following. ...
Arbuja's user avatar
  • 71
2 votes
0 answers
89 views

How can I make this "Pick" inside a "Table" run faster?

I am working on becoming more and more familiar with MMA and on a scale from one to ten, I would rate myself as a four or a five. I understand vectorization and that loops-are-very-bad. I have ...
Fixed Point's user avatar
3 votes
2 answers
331 views

Extract outputs from a WHILE loop in a table format

How can I convert my multiple outputs of a while loop in a table form and save it for later use. Here is a sample code: ...
primefinder's user avatar
14 votes
2 answers
1k views

Map vs. Table for index-specific operations on 2D arrays

Many experienced users on this site tend to use Map (and its variants, MapAt, MapIndexed, etc.) rather than Table. When applying the same operation to every element of an array, Map does seem more ...
theorist's user avatar
  • 3,633
1 vote
1 answer
35 views

RecursionLimit errors on Manipulate a DensityPlot expression

I am trying to do an interactive visualization of a very simple neural network (inspired by tensorflow playground): ...
Carlos's user avatar
  • 113