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
4
votes
2answers
74 views

Limit solution domain in Solve

How should you write the Solve command or another to give me solutions to this equation for example integers rationals Here are the equations: ...
19
votes
1answer
155 views

Why does OperatorApplied by default reverse the arguments?

Perhaps this is just one of those Mathematica curiosities, but I'd like to know why by default OperatorApplied[f][x][y] === f[y,x] versus the more usual way one ...
5
votes
2answers
159 views

Is it possible to pipe(afterthought apply function) with options?

For example, I have the following ...
0
votes
1answer
50 views

Define derivative as a new function

I’m coding my first physics simulation in Mathematica, and have a problem. I want to do the following inside a single cell input. ...
28
votes
4answers
34k views

How do I identify the source of a “Tag times protected” error?

I have some code that looks like Table[ a = 1; b = {2, 3} c = i;, {i, 2} ] which gives an error: Set::write: Tag Times in c {2,3} is Protected....
3
votes
4answers
95 views

Interpreting an ODE solution from DSolve

I'm doing a project where I need to solve an ODE. . I tried using DSolve to solve it, and it gave me an answer, but I'm unsure how to interpret it. The code I'm ...
0
votes
1answer
47 views

Correct syntax for tensor operators?

So I have an operator $A_0$ whose matrix representation is given by $$A_0 = \begin{pmatrix} 0 & -i \\ -i & 0\end{pmatrix},$$ and I also have two vector states $|0\rangle$ and $|1\rangle$ ...
1
vote
1answer
37 views

Issue with Compile for Complex Input/Output

I'm writing a Runge-Kutta algorithm for solving a system of coupled differential equations. My code works fine when defined as a module, but when I try to compile it, I get the following error: ...
2
votes
2answers
72 views

Isn't there a better way to display mathematical equations as labels, in Manipulate[ ] etc.?

I often want to output a mathematical equation in a text environment, and I find it very cumbersome and often the result is also not satisfactory. This example out of the "Advanced Manipulate ...
2
votes
2answers
299 views

Why does 'Transpose[list]' work but 'Map[Transpose[#]&, list]' not when attempting to transpose a 2D-array list? [closed]

I define this list: list={{100,100},{200,200}} Taking the transpose like this works as intended: Transpose[list] Taking ...
0
votes
0answers
46 views
30
votes
1answer
655 views

Is there a linter to help write good Mathematica code?

I don't do much real programming, but I've recently been turned on to Atom, which has linter plugins for over 50 languages to make coding easier (most drawing on pre-existing lint-like programs). In ...
1
vote
2answers
52 views

Problem with internal variable of a `Module` which returns the solution of an `NDSolve` command. y$25947 → InterpilatingFunction[…]

I will try to give a minimal example of my problem. Say I define the following function, spitting out an NDSolve result, using ...
1
vote
0answers
22 views

Manipulating a system of equalities into particular form

newbie here just trying to learn the Mathematica syntax. I have a list of equations, some of them definitions, others relationships, as follows: ...
1
vote
2answers
43 views

Plotting a complete response to an oscillation; already have particular solution, not sure how to solve for constants in homogeneous solution

I am writing a code that plots an oscillator's response to a periodic excitation. The response consists of the following: x(t) = xh + xp where xh is the homogeneous solution and xp is the particular ...
0
votes
1answer
26 views

How to add multiple paths?

What I am trying to do is generate random data based on a normal distribution and plot different paths of the process. But how can I add multiple paths instead of repeating the process over and over ...
0
votes
1answer
47 views

How to use RandomVariate on a random process? [closed]

I am trying to generate random numbers based on a white process WhiteNoiseProcess[]. Here is my code: ...
1
vote
1answer
23 views

syntax error when defining a list of matrices: “…cannot be followed by..”

I am literally just defining a list of matrices, but seem to run into the following error when adding the last matrix. (so to be clear, I get no error when I take out the last matrix entry). What's ...
1
vote
0answers
42 views

Loop over variable sized arrays

I would like to build an Encoder/Decoder to export my Data from Mathematica to Julia. From Mathematica I get arrays of variable dimensions, these arrays contain variables that don't have a fixed value ...
3
votes
0answers
106 views

Different execution behaviour between Wolframcloud and Wolfram Mathematica

When I execute in Wolfram Mathematica: s=0.3; m=5; x=6; it works. But when I execute the same on wolframcloud.com it returns ...
9
votes
4answers
495 views
0
votes
0answers
22 views

MakeExpression : Input Form error even with perfectly written expressions

I am frustrated by this MakeExpression error which sometimes shows up and sometimes doesn't for perfectly written expressions. How do I tackle this error? What is wrong with my code? ...
0
votes
0answers
76 views

Is it possible to create the following simulation in mathematica?

Consider a set of discrete "states" $|1\rangle,|2\rangle,|3\rangle,\dots,|N_{\text{max}}\rangle$). Next, assume that there are 1000 "particles" occupying the state 1 at the initial moment of "time". ...
2
votes
0answers
40 views

Why do comments sometimes become Null instead of being removed completely?

Consider the following definition: Piecewise[{{(*comment*)-1, x > 0}, {0, True}}] This is interpreted as intended, with the comment being simply removed, ...
7
votes
1answer
215 views

Problem overloading D[] using UpValues

First I define an entry of UpValues overloading D[] for expressions with head ftest: ...
1
vote
1answer
64 views

Partial Differentiation in Mathematica, syntax error? [closed]

I am trying to differentiate some random function using Mathematica at particular nodes, I am though not being able to implement this without being retrieved the following error message: D: ...
0
votes
1answer
92 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]...
0
votes
0answers
22 views

Domain of definition for the following variables: is it possible to derive in Mathematica?

Consider 4 4-vectors $$ P_{0} = (E_{0},0,0,\sqrt{E_{0}^{2}-m_{0}^{2}}), \quad P_{i} = (E_{i},p_{i}s(\theta_{i})c(\phi_{i}),p_{i}s(\phi_{i})s(\theta_{i}),p_{i}c(\theta_{i})), $$ with $c \equiv \cos, s \...
1
vote
1answer
71 views

Solving an equation for a power of unknown variable

How do I solve an equation for a power of $t$, e.g. solving $$-t(x–8)/8 = –2(x+4)/t$$ for $t^2$ instead of $t$, i.e. to get the answer $$t^2=16(x+4)/(x–8)$$ from ...
0
votes
1answer
37 views

Extract solutions in an interval for a trigonometric equation

Consider the solution x1 = x /. Solve[{Cos[x] + Sin[x] == 0}, x] The output is a conditional expression or, with //Normal, a ...
0
votes
1answer
36 views

What does <<2>> mean in an output? Double Less than or greater than signs [closed]

An error in my output gives I am trying to understand what the issue is. I was wondering if this <<2>> has anything to do with it, because I don't know what that syntax means. Is <<2>> ...
3
votes
1answer
85 views

Map substitution of variable in expression

If I have an expression involving a variable x, like 2x+1, and I have a list of different possible ...
0
votes
0answers
25 views

Clear assigned y'[x] from memory [duplicate]

If I, by mistake, write Mathematica assigns $y'(x)=y(x)/5$ and I don't know how to clear that from memory (I had to restart Mathematica). ...
4
votes
1answer
107 views

Plot a graph with an uncertain number of tangents

The code below tries to illustrate a graph ($y=(2-x^3)/x$) that can have 1-3 tangents depending on the tangent point $a$. ...
0
votes
2answers
59 views

Unable to find the exact dimension of an expression

I have defined a variable called y, this contains a huge equation, but when I look for the dimension of y it shows 3. How come a single expression has dimensions of 3? It is supposed to be 1 right? <...
0
votes
0answers
30 views

TagSet::sym Error using Subscript [duplicate]

I am a beginner to Mathematica and I am trying to get it to solve some equations of a function (vector) $B$ of three components, but first I want it to know that the derivates with respect to one ...
82
votes
1answer
2k views

Incompatible Changes since Mathematica Version 7?

There is documentation of the incompatible changes made to Mathematica with each major release: Incompatible Changes since Mathematica Version 1 Unfortunately that documentation simply stopped ...
2
votes
0answers
125 views

Model 1D Vlasov Equation

Vlasov Equation The non-relativistic form of the Vlasov equation is given by: $$ \partial_{t} f\left( \mathbf{x}, \mathbf{v}, t \right) + \mathbf{v} \cdot \nabla f\left( \mathbf{x}, \mathbf{v}, t \...
1
vote
0answers
38 views

Two point Gaussian quadrature [closed]

I am trying to calculate a two point Gaussian Quadrature on the interval [0,4] and the function f_n = (x^n) + 2 x - 3 for ...
7
votes
1answer
714 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 ...
0
votes
2answers
40 views

Assuming variables are real and positive [closed]

I thought the following code would work, ...
4
votes
3answers
131 views

How to implement an integration filter on arrays?

I have the discrete integration filters: $$y(n) = Ax(n) + By(n−p) , \text{$A$, $B$ real constants, $p$ positive integer}$$ EDIT: in the initial version of this question I focussed only on the case $...
9
votes
1answer
432 views

Why is Reap result nested? [closed]

A minimal (toy) example for my question: i= 1; Reap[Do[Sow[i = (i + 1)^2], {4}]] (* {Null, {{4, 25, 676, 458329}}} *) I presume the entire result is a ...
7
votes
2answers
325 views

Internal Representation of ?name and ??name

Code FullForm[Hold[?name]] Syntax::bktmcp: Expression "Hold[?name]]" has no closing "]". Syntax::sntxi: Incomplete expression; more input is needed . Question ...
3
votes
1answer
101 views

RegionCentroid and center of mass

If we have three masses $m_1,m_2,m_3$ (assuming that are all equal to $1$) located at $r_1,r_2,r_3$ respectively, then the center of mass is at $(1.00,0.83)$. In the Wolfram Documentation page says ...
1
vote
1answer
73 views

Basic Question: how should I read this instruction?

I'm very new at using Mathematica and it's not my Job. It's just something I like. ...
0
votes
1answer
33 views

Real value of a complex expression

Why is the following lines not correct? Clear[a, b] a \[Element] Reals; b \[Element] Reals; f[z_] := z^2 + 3 z - 2 g = f[a + b I] // Expand Re[g] The output ...
0
votes
1answer
75 views

How this equation is solved in reals

I have tried to solve this equation $2^{-2 ^{2^{-x}}}=2$ using FindInstance[2^(-2^(2^(-x))) == 2, x, Reals] The result is ...
0
votes
1answer
29 views

Excluding an imaginary, partial, part of solution from Solve

When I type the command Solve[{x + 1/x == y - 1/y, x^2 + 1/x^2 == y^2 - 1/y^2}] // Simplify // N I get a 'close to zero' imaginary part, ...
0
votes
1answer
37 views

Expression with Boole

Let us have an expression for example, this: 2 (-1 + p) (3 - 4 p + 2 p^2) Boole[\[FormalX] == 1] - 9 (1 - 2 p + p^2) Boole[\[FormalX] == 2] ... For the whole ...

1
2 3 4 5
15