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
2
votes
1answer
46 views

Code not working when I'm breaking it up into different lines

The following code works perfectly For[i=1,i<4,i++,Print[i]] However, when I break this into different lines, it stops working. Moreover, the braces appear to ...
0
votes
0answers
31 views

what is the difference between /. and /; in mathematica? [duplicate]

What is the difference between /. and /; in Wolfram Mathematica How would you apply them both and what situations are each of them appropriate to use?
1
vote
1answer
30 views

ContourPlot a list of equations generated by the Table command

The first command below produces proper contour lines while the second command produces an empty plot. I would think that the two commands should produce the same output. What's going on? ...
1
vote
4answers
85 views

Adding plot options after @ in ListLinePlot [closed]

How can plot options like PlotLabel and PlotRange be added after @ in ListLinePlot? For example: ...
8
votes
1answer
600 views

Correct way of simplifying the result of an integral

Many times Mathematica gives enormous results to simple problems. One uses the program more for trouble than for not knowing how to solve the problem. As an ejemplo I present this integral that ...
10
votes
7answers
1k views

How to take the beginning and end parts of a list with simpler syntax?

So basically you have a table of some values, let's call it a: a=Table[n,{n,10}]; (*{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}*) And you ...
6
votes
3answers
465 views

Is $2x$ documented?

According to the official documentation of Times[], multiplication of $x$ and $y$ is represented as one of x*y x×y ...
5
votes
2answers
477 views

Game schedule where each player meets only once

I am trying to generate a game schedule where $k$ players at the time, out of $n$ participants, meet in each game, but any player meets another player only once. In each game, with $k$ simultaneous ...
0
votes
0answers
36 views

Definition of a matrix [duplicate]

...
5
votes
5answers
273 views

Integral of the integral using NIntegrate

Consider the integral NIntegrate[Exp[-NIntegrate[x, {x, 0, y}]], {y, 0, 2.8}] It displays an error ...
2
votes
1answer
83 views

Syntax highlighting indicates I'm unable to comment properly in Mathematica using (**)

I wanted to "comment" some code so the input inside (* *) is ignored. I tried this but the last term z[3] looks like it is not ...
4
votes
3answers
271 views

Through: how to use it with subtraction of functions?

As the documentation says the command Through works as it follows: f[x_]=x; g[x_]=x^2; Through[(f+g)[x]] --> x + x^2 Like ...
5
votes
1answer
66 views

How to create a 2D table with varying step?

I would like to produce a table with 2 coordinates, where a step for one coordinate depends on the value of another one. I tried to do this in the following way: ...
6
votes
1answer
229 views

Best way to write an equation with subscripts and superscripts

This post is not about a specific Mathematica problem but about to develop the best way to enter mathematical equations with subscripts and superscripts. I have a ...
5
votes
1answer
73 views

Variable dimensional integrals

I need to Integrate a function, but let the number of dimensions vary. Integrate[Product[Exp[-( t[[i]] )^2], {i,1,4}], options] ...
1
vote
1answer
30 views

Behavior of PlotLegends

I want to have a plot of $x^{\alpha}$, where $\alpha$ is an input, and a plot legend which displays something like $\alpha = \# \text{ rad}$ on the following plot, where # is determined by the input. ...
0
votes
1answer
47 views

How to create the progress indicator for the following process?

Consider the code Table1[m_]:=Table[{m,NIntegrate[Exp[-I*m*x],{x,0,1000}]},{i,0,8000,1}] Table2=Join[Table1[1],Table1[5],Table1[0.2],Table1[0.08]] How to create ...
0
votes
1answer
66 views

How to make split tables in Join?

I have a command Table0[mS_]:=Table[{mS*i,i^2},{i,1,20}] Table1=Join[Table0[1],Table0[2],Table0[3]] When calling Table1[[1]] I expect to get the element Table0[1]...
1
vote
0answers
120 views

Light beams reflecting from parabola

How can we show the paths of three light beams in Mathematica which bounce back after hitting the parabola, in a single plot? Suppose we have the following code ...
2
votes
1answer
115 views

Mathematica just takes infinite time to solve this

Can You help? I don't even care about the exact solution. I will be satisfied by the series expansion of the result around a=0. I tried to solve by series expansion and the same result .. infinite ...
0
votes
0answers
25 views

RegionPlot fails

Consider a function f[x_,y_]:=NIntegrate[g[x,y,z],{z,1.1*x,3000}] where g[x,y,z] is some function. The function f[x,y] is smooth and works perfectly when Plot it....
0
votes
0answers
54 views

How to handle the instability of the integral evaluation in the following case?

I want to integrate a function \[Kappa][gh, ms, ts, th, ph] (for all definitions, see a code below) with the distribution ...
0
votes
3answers
60 views

Removing the square-brackets and their contexts from an expression

Suppose I start with an expression like y[t] + x[t]: is there a function that lets me remove the [t] elements, so I obtain the ...
0
votes
0answers
17 views

Dot product returns symbolically when undesired [duplicate]

StateProb[state_, projector_] := Dot[state, projector, state]; StateProb[state1, Projector[{-(I/Sqrt[2]), 0, 0, 1/Sqrt[2]}]] State is {1/Sqrt[2], 1/Sqrt[2], 1/...
9
votes
3answers
203 views

How can I automatically replace [[ and ]] with the \[LeftDoubleBracket] and \[RightDoubleBracket] operators?

When you type ->, it is automatically turned into the \[Rule] character. Can we configure our frontends to do the same for ...
3
votes
1answer
108 views

Where to find order of arguments for default functions

Lets take for example the Laplacian. So I want to apply it in spherical coordinates, so I go the the associated documentation page (https://reference.wolfram.com/language/ref/Laplacian.html?view=all) ...
1
vote
0answers
61 views

Difficulty with ExternalEvaluate

I am trying to import a Python function or execute a Python script from inside Mathematica, but the ExternalEvaluate command drives me nuts. I proceed cautiously ...
3
votes
2answers
106 views

Overloading a function to pass in an expression rather that the name of a function

This is an example of procedural programming borrowed from Paul Wellin's book. It's a simple implementation of the Newton-Rhapson method. I overloaded the findRoot ...
4
votes
3answers
92 views

EntityValue timeline

I try to use EntityValue to get the returns of a stock from January 1st 2019 to today. When I use ...
0
votes
0answers
29 views

Having difficulties using results returned by Solve

I'm new to Mathematica, and I am still having some issues figuring out the general syntax. I've got to use Mathematica, as my research requires a powerful symbolic math program. I'm having trouble ...
6
votes
2answers
115 views

Separation of statements vs “space mul”, formal definition of Mathematica syntax?

In Mathematica, space can often be used to indicate multiply. For example "a b" = "a * b". On the other hand, in a *.m file, we also have multiple statements separated by newlines. How does the ...
0
votes
0answers
111 views

Remove background image and redraw lines in black

I do not know if the title is correct. The image that I upload has liked me a lot because of the characteristic that no matter the angle it seems that it is looking at you, you could indicate me how ...
10
votes
1answer
138 views

Why does Success[…][key] work and Failure[…][key] doesn't work?

I'm trying to figure out what is a quick way to add error reporting to my user defined functions. I was experimenting with Success and ...
1
vote
1answer
47 views

ListCountourPlot does not show any result [closed]

I was trying to show the heat conduction of Laplace equation problem.But the plot does not show properly ...
5
votes
2answers
97 views

Converting prefix to infix

Is there a way in Mathematica to convert prefix to infix notation (where precedence order is preserved)? For example, how would I convert S[a, S[b, c]] to ...
8
votes
2answers
215 views

Finding the point closest to a parameteric curve produced by a numerical method

Question How can I find the closest point to a parametric curve produced by a numerical method. General Context I have a parametric curve (which I will call $g$) produced from a averaging many ...
3
votes
2answers
87 views

Trying to plot the norm of the solutions to NDsolve

I have been tried to do two things with the solutions from NDSolveValue plot the norm of the solutions of a differential equation system versus time. plot one component of the solutions of a ...
0
votes
0answers
31 views

How to automatically see user defined function arguments list?

Having typed a user-created function's name I would like to be able to see either the concise syntax dropdown available for inbuilt functions (shown below left) or alternatively to be able to see the ...
0
votes
1answer
44 views

Maximize function subject to condition [closed]

What commands should I use in Mathematica to obtain the maximum or minimum of a function subject to conditions? For example, find the maximum of the following function? $\qquad T=\sqrt[3]{2\,x+5} + \...
1
vote
1answer
67 views

Defining iterative algorithms [closed]

Assume the iterative algorithm of interest to be as follows: ...
0
votes
0answers
32 views

Syntax Error, Text Style and escaping characters

I have a weird error (I guess it could be called a bug), where a file containing the text line (as in in a cell you create with Alt-7) gives a syntax error when called from the terminal using ...
1
vote
1answer
102 views

Rotation in physics [closed]

I have a mathematica problem in theoretical physics: There is a rotation axis $\vec{n}$ with $|\vec{n}|=1$. Each other vector $\vec{v}$ can be seperated in relation to $\vec{n}$ in a parallel part ...
2
votes
1answer
45 views

What's the difference between $Context<>“*” and “`*”?

When set context unique to this notebook: ClearAll @@ { $Context<>"*" } Clear["`*"] can both clear the variables I assigned. I just wonder what's the ...
2
votes
1answer
68 views

center of mass, total momentum

Has someone an idea how to solve the 1. question for ANY number of mass points and a clue to the 2. question? center of mass system, momentum
0
votes
1answer
84 views

center of mass system, momentum

when I have systems with 3 mass points ($m_i, i=1,2,3$) to a time $t=t_0$ on positions $\vec r_i(t_0)$ and velocity $\vec v_i(t_0)$. How could a syntax look like to calculate 1) center of mass 2) ...
3
votes
0answers
46 views

Pure function: using T[[#]] where # indicates a position [duplicate]

When using T[[#]] in which # indicates a position, how do you pass on the position # (which ...
0
votes
0answers
61 views

Implementing a function that exhibits linearity

I am trying to define a function $\mathbb{E}_t$ such that $\mathbb{E}_{t}[f[x_{s}]] = f[x_{s}]$ if s<=t, and $\mathbb{E}_{t}[f[x_{s}]] = \mathbb{E}_{t}[f[x_{s}]]$ if s>t. $\mathbb{E}_{t}$ is ...
0
votes
1answer
78 views

Plotting the condorcet jury theorem [closed]

I am trying to create a simple plot of the condorcet jury theorem: The function is: F[n_,i_,p_]:=((n!)/((n-i)!*i!))*((p^i) *(1-p)^(n-i)) embedded in a sum ...
0
votes
0answers
34 views

Is there a difference between these two ways to define a function? [duplicate]

(I took this example from another question) f[0] = 0; f[n_] := f[n] = DigitCount[n, 10, 1] + f[n - 1]; f[1016] I notice that this example defines f(n) in a ...
1
vote
1answer
70 views

Harmonic number of $r$ with order $r$ [closed]

Mathematica recently offered me this expression as the result of an evaluation: HarmonicNumber[r, -r]. I initially thought this must be equivalent to ...