18
votes
When is ##@@@##& more appropriate than ##@@##&?
It's a beginner's error to put @@@ before @@:
...
- 226k
12
votes
Accepted
12
votes
Accepted
How can I digitize the vector figure?
This answer seems to be version-dependent. It was created with
$Version
13.2.0 for Microsoft Windows (64-bit) (November 18, 2022)
Okay, let’s do this.
We start ...
- 5,235
10
votes
How to force fit of the data to exactly match one of its points?
The right way
You say your model is
model = ( y == a*x + b*x^2 + c )
that is, three free parameters {a,b,c}.
But in reality, ...
- 35.2k
8
votes
Accepted
How can I write this using fewer variables?
Since OP asks about good programming practice, my answer in this case and in general would be: Write useful functions. Maybe one can add: Avoid global variables, which often means using ...
- 11.6k
7
votes
Accepted
Why the ugly code is faster than the pretty code?
The issue seems to be that you use
coordx1 = coordx[Tab1[[i]][[indexE]], M, Tab2[[j]][[indexE1]]];
instead of
...
- 101k
6
votes
Accepted
Using Compile with vector expressions
Using a pure function
vec = Function[{x,y,z},{x^0.5*y^0.1,y^0.3*z^0.1,z^2*x*y}];
and inlining works:
...
- 11.6k
6
votes
6
votes
How to transform the output regarding exponentiation?
One option is to use CForm to do the heavy lifting, followed by StringReplace to apply the final tweaks (e.g. renaming functions ...
- 30.2k
6
votes
Annular cylinder with varying dimensions
Method-1
At first we draw the sectional graphics;
...
- 52.1k
6
votes
Accepted
How can I replace the locally defined function inside If with its value?
Your issue results from the fact that If holds its second and third arguments:
Attributes[If] (* {HoldRest, Protected} *)
This ...
- 5,021
5
votes
Accepted
5
votes
How to get + ... notation at the end of a serie sum
how to add +... to the end of series sum ?
ser = Normal[Series[1/(1 - x), {x, 0, 10}]] + \[Ellipsis]
You can use Basic typesetting Pallettes
- 127k
5
votes
How to collect specified monomials in polynomial?
Normal @ Last @ CoefficientArrays[poly, subs]
- 356k
5
votes
5
votes
Using Compile with vector expressions
I understand that the question is about Compile, but this is a case where it is easy to get fast code without compiling: Assuming OP's definitions
...
- 11.6k
5
votes
Symbolic manipulations of predefined variables without numerical substitution
You need only one Hold if you do it like this
x = 4; y = 4;
Block[
{x, y},
Hold[ Evaluate @ Expand[(x^2 + y^2)/x^2] ]
]
...
- 35.2k
5
votes
Accepted
5
votes
Accepted
Solve Equation with NSolve
$Version
(* "13.2.1 for Mac OS X ARM (64-bit) (January 27, 2023)" *)
Clear["Global`*"]
From the documentation, "NSolve deals primarily ...
- 139k
5
votes
Accepted
How to keep the code compact in the following case?
I'd recommend to leave all the fluff away and to simply write two loops with a single branching to decide which loop to evaluate. Moreover, it might be a good idea to use boolean arithmetic (i.e. <...
- 101k
5
votes
Accepted
How to make a plot over some external figure?
You can use Prolog and Inset to position the image behind the plot, but some calibration is needed to get correct coordinates.
...
- 11.8k
4
votes
4
votes
4
votes
How can I subtract and calculate the complement of a pair of sets?
First, do not use capital letters for variables, because capitalized names are used by the system.
A set difference, e.g. c-a, is written by: Complement[c, a]. A set union, e.g. of a and b, is written ...
- 37.4k
4
votes
Accepted
How can I subtract and calculate the complement of a pair of sets?
In Mathematica, your P and Q can be written as:
P = Complement[b, c] ⋃ Complement[c, a ⋂ b];
Q = Complement[b, a] ⋃ Complement[a, b] ⋃ c;
To avoid mistakes when I ...
- 19.5k
4
votes
4
votes
How to calculate different combinations of back and dotted perimeter
All the arc lengths are equal to Pi/6. For example,
...
- 52.1k
4
votes
Accepted
String to expression does not work properly
The smallest fix would be to change the final _ to ___. I.e. the pattern would look like this:
...
- 15.5k
4
votes
Accepted
Dealing with locally defined functions in Module while exporting/importing
You may benefit by using Pure Functions
...
- 35.2k
4
votes
How can I replace the locally defined function inside If with its value?
I may not be grokking what you're going for, but maybe this:
...
- 15.5k
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
syntax × 906functions × 79
list-manipulation × 78
function-construction × 64
plotting × 59
programming × 43
equation-solving × 41
calculus-and-analysis × 40
differential-equations × 35
evaluation × 33
core-language × 28
numerical-integration × 23
matrix × 22
symbolic × 22
performance-tuning × 21
warning-messages × 21
replacement × 20
symbols × 19
custom-notation × 18
compile × 17
expression-manipulation × 16
operators × 16
simplifying-expressions × 15
mathematical-optimization × 15
front-end × 15