Questions tagged [syntax]

Questions on correct (or improved) formulation of Mathematica code to achieve particular results. Use this tag (not "symbol") for questions about all those odd @@ /@ # & and ~ characters.

Filter by
Sorted by
Tagged with
8
votes
1answer
2k views

How do I begin to plot an electric field for two point charges?

I'm using Mathematica for the first time and I believe I am having trouble with the syntax. I'm trying to plot a two point electric field and the first step in getting an electric field plot would be ...
4
votes
1answer
168 views

How to download Entity data for an interval of dates

I am interested in downloading "TropicalStorm" data for hurricanes with the highest "WindSpeed" occurring in the years 1990 ...
3
votes
0answers
70 views

Use of ContainsAny in EntityClass

The documentation page for EntityClass states that Property values in implicitly defined entity classes may make use of Quantity (and intervals of Quantity) for ...
8
votes
6answers
2k views

How to efficiently input matrices in Mathematica (compared to what MATLAB offers)

Every time I want to manually input a matrix in Mathematica, it takes me a while since every new row has to be in a separate pair of curly braces. For instance: ...
1
vote
3answers
182 views

Writing a conditional expression [closed]

I want to test a specific condition on z1 and z2 such that if z1 is greater than zero and <...
1
vote
1answer
658 views

How to extract the first and last element

It is a elemental question maybe,but I am confusing still.If I have a 1-dimension list list a = Range[5] (* {1, 2, 3, 4, 5} *) ...
1
vote
2answers
96 views

How to make a address to string

I get a Window address,Of course it should be a string in generally,but I got a non-string by some method,such as paste your clipboard into your notebook directly or other ways.I want to do some ...
4
votes
2answers
179 views

Letter g rendered with different descender styles

I've just noticed that Mathematica renders g in two distinct ways: either with a closed descender or a open descender. Seems it happens only for local variables. g ...
-1
votes
1answer
136 views

What is a proper way to express derivatives with respect to a symbol? [duplicate]

Mathematica's default way of representing derivatives is to express them with respect to a function's input slot. But what if I want to use the chain rule? To replace df(x)/dx with df(0.5 y)/dy 0.5, ...
1
vote
0answers
57 views

Why is my array not displayed in TableForm? [duplicate]

Why is the array produced by the following not displayed in TableForm? ...
0
votes
1answer
74 views

Why is Carbon and other elements (not available) in StoppingPowerData?

I am trying to look up StoppingPowerData for a number of elements and while this snippet works for several I have tried (Aluminum, Lead, Iron for example), I get a result of (not available), but no ...
2
votes
0answers
29 views

How to search effectively for information on MMA Syntax such as “_?” [duplicate]

In another question here, I saw this poincareMetric[u_?VectorQ, v_?VectorQ] := ... Whilst I am familiar with the syntax label_Type, e.g. x_Real, I had not seen ...
1
vote
1answer
475 views

How could I define function with function such as Coefficient? [duplicate]

For example, I have eq1=ax+by+cz; and then I want to define new function, $eq2$, as eq2[x_]:=Coefficient[eq1,a]; eq2 ...
1
vote
2answers
214 views

How to return the unevaluated variable names from a list of variables which have been declared

I feel like this should have a simple answer but I haven't found anything that works. The toy example of what I want is as follows: ...
2
votes
1answer
142 views

Using Case to pull Keys and Values out of a nested Association

The set up: First a helper function: Clear[values] values[m_, l_, v_] := <|"Math" -> m, "Log" -> l, "Value" -> v|> I have a nested Association of ...
0
votes
2answers
117 views

How to put the result(and its specified variable) to clipboard

I have a such custom function to do some complicated thing: customFun[str_] := Defer[StringJoin["abc",ToString[#]]&@*StringLength][StringDrop[str,{1,-1,2}]] ...
1
vote
2answers
109 views

Roots of an equation output [duplicate]

I'm trying get the critical points of the function $f(x)=(( 1 - 3*(x + 1)^3)/(x^4 + 1))*(x - 2)$ so I took the derivative which is $(16 + 18 x - 9 x^2 - 28 x^3 - 48 x^4 - 18 x^5 + 3 x^6)/(1 + x^4)^2$ ...
5
votes
3answers
146 views

Unexpected behavior of MapAt

For the description, I have a simplified problem like the following: MapAt[f[1, #1], {a, b, c, d}, #2] & @@@ {{1, 2}, {3, 4}} will give ...
0
votes
1answer
121 views

Can't get the correct answer with this Adaptive Simpson's Rule algorithm

I think the mathematical portion of my algorithm is correct, but I don't really know the mathematica syntax. How do I get the actual function to be evaluated? Code: ...
4
votes
1answer
80 views

Why am I getting different answers for expressions containing x^(1/2) and x^(0.5)?

I'm doing a constrained optimization function, where I maximize a function with two arguments subject to a simple constraint: ...
1
vote
0answers
60 views

Assigning variables from rules from fit

It became quite clear after running this a few times that my syntax is wrong, but I can't parse out why. Anybody know of a better way to write this? ...
5
votes
3answers
233 views

FillingStyle->{None,Automatic} gives unexpected results?

Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {None, Automatic}] produces an outcomes I find unexpected: In contrast, ...
1
vote
1answer
45 views

Learning Shortcut Syntax - Newbie Question [duplicate]

I'm learning Mathematica in order to work with Linear Algebra. I found a good post here about matrix manipulation, but realized that the author used conventions that I couldn't find documented in the ...
1
vote
2answers
107 views

Use Accumulate while creating Table

Can I somehow create a list and its cumulative sum at the same time, e.g. with Table: Now I do it in two steps ...
3
votes
1answer
462 views

List positions without brackets [duplicate]

Suppose I have a list l which contains the indices of some array a. For instance, l = {{1,1},{1,2}} a = {{a11,a12},{a21,a22}} I want to access the elements of a ...
0
votes
1answer
513 views

Using Newton's Method to solve system of equations

I am getting an error that just gets stuck formatting notepad, i don't think there's anything in my code that is wrong, but I'm never sure. ...
1
vote
0answers
181 views

Creating 3D image from importing 2D images [closed]

I'm trying to recreate a 3D image from it's 2D slices. I have saved the 2D images as "image1, image2, etc". I've imported them this way: ...
6
votes
1answer
76 views

Non-trivial partitions of numbers using Combinatorica

I have made a code which gives back partitions of numbers in two Young diagrams (one Young diagram is trivial). For example, the partitions of 1 are ...
0
votes
0answers
91 views

Solve / Reduce runs overnight - should I keep waiting?

I'm pretty new to Mathematica and I'm trying to solve a system of two equations, but both Solve[] and Reduce[] have been running ...
1
vote
1answer
194 views

System of nonlinear complex-valued equations using Solve

I'm trying to figure out the proper syntax to use in Mathematica to solve the following system of $6$ nonlinear complex-valued equations in $6$ unknowns $a,b,c,d,e,f$, where $a,d,f \in \mathbb{R}$ and ...
4
votes
2answers
536 views

Mathematica can't differentiate when variable name has subscript component

I am not pasting my input code here since the website modifies my code. Instead I am attaching a screenshot of my notebook. Issue: I enter two separate commands (asking Mathematica to differentiate ...
1
vote
1answer
53 views

User Defined Functions Not Implementing HoldForm in list of Functions

When I insert the following code in Mathematica, f[x__] := Map[HoldForm, {x}]; g[x_] := x^2; f[g[t], Cos[t], Tan[t]] I get ...
0
votes
1answer
189 views

How can I make Mathematica compute an operator?

I would like Mathematica to write down the Laplace-Beltrami operator in $R^N$ $$ \Delta f = \frac{\partial^2 f}{\partial r^2} + \frac{N-1}{r} \frac{\partial f}{\partial r} + \frac{1}{r^2} \delta f, $...
2
votes
3answers
681 views

Minimize function with parameters: how to properly define constraints on the parameters

I am trying to find a minimum of a function consisting of variables and parameters, where I only want to minimize with respect to the variables while defining constraints on the parameters. To ...
1
vote
0answers
95 views

Decimal alignment in a grid

I tried to find an answer and found quite a few posts on similar topics, but none of them really helped me. Here is a typical example: ...
8
votes
0answers
118 views

What does the pair “\<” and “\>” in a string do? [duplicate]

What do \< and \> mean inside of a string? ...
6
votes
1answer
143 views

Why 2^^1*^k does not work?

Table[2^^1*^k,{k,0,10}] This gives an error, why is that? Also this BaseForm[2 ** 1*^ #, 16] & /@ Range[10] What is ...
2
votes
2answers
352 views

Trouble with MODULE [closed]

I try to become familiar with the Modules and struggle :-( I wrote a very very pretty example but got an exception: ...
1
vote
0answers
226 views

How to get user input using FormPage

I am designing a user interface for a word-ladder game using CloudDeploy, CloudExpression and FormPage and I am having trouble with receiving the user input from the form. What I basically need is a ...
3
votes
1answer
82 views

How to speed up accidental large output?

From time to time I accidentally let large expressions like RandomReal[1., {10^5, 10, 10}] reach the front end. The computation of the result is quite fast (...
9
votes
1answer
213 views

Why is this syntax for patterns with Optional values not supported?

I want to express Optional[PatternTest[Pattern[a,Blank[]],t],1] concisely. a : _?t : 1 is not quite this but works: ...
7
votes
2answers
508 views

Updating a parameter each time step within a Finite Difference scheme?

So I am solving a PDE for a function $h(\theta,t)$ via finite difference scheme. The PDE has a function $Q$ in it, which I wish to update each time step depending on where $h$ lies. Firstly, let us ...
9
votes
4answers
309 views

How to avoid repetitive calculation when doing numerical integral?

Suppose I have a function f[x] which is very complicated, together with a function g[f[x]]+h[x] to integrate. That is: ...
1
vote
0answers
64 views

Simple list manipulation [closed]

I have two lists: {1,2,3} and {a,b,c} and I want this result: {{1,a},{2,b},{3,c}}. What is the right command? How does one call such an operation?
10
votes
1answer
1k views

Should I add a semicolon after a function definition? [duplicate]

should I write the program like this: f[x_]:=x^2; g[x_]:=x+2; or should I write the program like this: ...
4
votes
2answers
164 views

How to calculate this probability?

Here I want to find the probability $p$ which is given by $$p=\int_0^{r_d}\mathcal{L}_I(\beta r^{\alpha}|r)f_R(r)dr$$ with $r_d=1$ and $0 \le r\le r_d$. I want to calulate the probability for ...
5
votes
2answers
94 views

Grouping/precedence for “/@” operator

This returns errors: {#[[1]],#[[3]]} & /@ {#[[1]],#[[2]],#[[3]]} & /@ {{"A","B","C"},{1,2,3}} Part::partd: Part specification A[[1]] is longer than ...
2
votes
2answers
141 views

How to create assignments to OverVector programmatically

I wish to write a function that accepts two lists. The 1st argument is a list of lists, holding the components of a several vectors. Ex.: comp = {{a, b}, {c, d}}. ...
6
votes
2answers
974 views

Plotting an equation describing a Joukowski airfoil

I am trying to plot an equation that will give me a Joukowski airfoil and am having trouble getting any results. The equation that I am using is as follows: ...
1
vote
1answer
155 views

integrating with multiple indicator functions depending on each other

I need to compute the following integral with three indicator functions, $I(x)$, $I_1(x_1)$ and $I_2(x_2)$, $$ \int_0^1\int_0^1I(x)\left( \ I_1(x_1)\,x_{1} + I_2(x_2)\,x_{2}-1 \right) dx_1 dx_2 $$ ...