# Questions tagged [wolfram-mathematica]

2608 questions

1

votes

1

answer

51

Views

### How to take the derivative of list inside a .dat file from Mathematica using Python?

I have a .dat file from Mathematica. It has two columns: the first column represents the pre-quench relative chemical potential ($\theta_{0}$), and the second column represents the average work done ($\braket{W}$).
0.0001 1.968765727
0.03151592653589794 1.526403743
0.06293185307179587 1.315922249
0...

1

votes

1

answer

49

Views

### Wolfram Mathematica - Minimization of an absolute error with respect to two parameters

I want to minimize the absolute error between numerical solutions of two nonlinear ODEs. Here is the code I use:
\[Epsilon] = 10^-6;
Delta[t_] := 1/(Sqrt[\[Pi]] \[Epsilon]) Exp[-(t/\[Epsilon])^2]
f[t_] := 1/2 (1 + Tanh[100 t])
solw = NDSolve[{w''[t] + (w[t] + w[t]^2) w'[t] == f[t], w[0] == 0,
w'[0]...

1

votes

0

answer

81

Views

### Solving coupled heat pde in mathematica

dC1/dt = -(Fp)(L)/Vp*(dC1/dx) - PSg/Vp(C1/Wp-C2) + Dp*(dC1/dx2);
dC2/dt = PSg/Visfp(C1/Wp-C2) + Disf*(dC2/dx2);
My boundary conditions are:
C1(t,x)|x=0 = Cin(t)
C2(t,x)|x=0 = 0
Cin(t) is a function of a known form e.g. Cin(t)= exp(-t);
dC1(t,x)/dx|x=0 = 0
dC2(t,x)/dx|x=0 = 0
dC1(t,x)/dx|x=L = 0
dC2(...

1

votes

0

answer

108

Views

### Fixed-Point Iteration Mathematica

This is a mathematica code for fixed point iteration.
expr={1,0,9999};
f[{i_,xi_,err_}]:=(xipp=0.2062129*(20+(2*xi))^(2/5);
{i+1,xipp,Abs[(((xipp-xi)/(xipp))*100)]});
NestWhileList[f,expr,#[[3]]>=.05&]
If I were to prove this converges for all initial guesses would I use the same code and replace t...

1

votes

1

answer

45

Views

### How to declare variable in Mathematica and use them later

I am very new to Mathematica and I was curious about how one can declare variable and use them later in function. I tried to do as below but I'm getting empty result in Graph
Here I've declared two variable one and two and tried to use them later but it didn't output the result.
Thanks in advance.

1

votes

0

answer

190

Views

### How to change the Range interval in x and y axis in Mathematica

Below is my Data of which I am using Mathematica to plot graph.
f[x_] := {x, Sqrt[2/(3 x)]};
ListLinePlot[f /@ {2, 10, 100, 10^4, 10^7}]
But If I increase the x axis range beyond 10^7, then It becomes straight line and almost became horizontal with x axis so it can't be distinguished. So I was tryin...

1

votes

1

answer

98

Views

### How to do numerical inversion of inverse laplace transform in mathematica?

I am trying to calculate the inversion Laplace transform of,
F(s) = Erfc[s]
at t = 100
I have tried the following way using Stehfest method(76 Mathematical Journal, 1994),
csteh[n_, i_] = (-1)^(i + n/2) Sum[k^(n/2)(2k) !/((n/2 - k) ! k ! ( k -1 ) !(i - k) !(2k - i) !), {k, Floor[(i + 1)/2], Min[i, n...

1

votes

0

answer

41

Views

### Ignore parts of an equation with multiple variable in Mathematica

I want to use the linear version of a somewhat big equation which is outputted by my Mathematica code - For simplicity I will here use the example equation:
Test = 3 x + x y + 8 y
Now, I want to use only the first order term, so that for x that will be 3 and for y that will be 8. I have tried to get...

1

votes

0

answer

85

Views

### How do I solve a matrix equation of non commuting variables in Mathematica

I would like to solve the system A*B=I for the elements of B in terms of the elements of A.
A and B are square, the elements of A and B don't commute (i.e. A[1,1]*B[1,1]=/=B[1,1]*A[1,1]), and A and B are of size nxn.
Here is what I've tried so far:
In[16]:= n = 2;
In[34]:= Reduce[Flatten[Table[
Sum...

1

votes

2

answer

62

Views

### Labeling edges in GraphPlot

I'm trying to animate the evolution of a discrete-time Markov chain, using the example on p. 30 of Kleinrock v. 1. This works pretty well:
p = {
{0, 3/4, 1/4},
{1/4, 0, 3/4},
{1/4, 1/4, 1/2}
}
Animate[BarChart[{0, 1, 0}.MatrixPower[p, n], PlotRange -> 1,
ChartLabels -> {'Kyoto', 'Tokyo', 'Osaka'},...

1

votes

0

answer

76

Views

### Mathematica 11.2 or 11.3 FrontEnd not working under Fedora 28

I cannot make the Mathematica notebook/front-end for versions 11.2 or 11.3 run under Fedora 28 (Wayland or Xorg). No error messages, no hints of a problem, just nothing happens. Worked with Wolfram and they correctly say that Fedora 28 is unsupported, however 11.1 FrontEnd works fine, and Fedora i...

1

votes

0

answer

135

Views

### Root finding inaccurate in Python?

I'm trying to solve a root finding problem in Python that should be pretty easy but so far has proven to be a tough nut. I've rendered the equations below as a function:
def fullsol(x, DIC, QCharge):
return [x[3] - (DIC/((1 +(K1/x[0]) + (K1*K2/(x[0])**2)))),
x[1] - (DIC/((1 +(x[0]/K1) + (K2/(x[0]))...

1

votes

2

answer

49

Views

### “outer” in python similar to Mathematica

I have an array of 2D positions (x,y) of a few particles. In Mathematica, I can use
Outer[Subtract, pos, pos, 1]
If pos is an array of shape (n,2) where n is the number of particles, the result of the above Mathematia code is a n x n x 2 array and each [i,j] element of this matrix is the result of...

1

votes

0

answer

16

Views

### Mathematica control of a USB spectrum analyzer?

I'd like to use Mathematica on Mac to control an RSA-306B spectrum analyzer (a USB device). Any Mathematica example of direct control of a USB device would be useful as I expect I could then modify for this specific device.

1

votes

0

answer

29

Views

### Loading dat file as array of arrays

I am quiete new in Python and I have already problems to load data from dat file, my data originaly produced in mathematica are in for of array of arrays:
1AL1.dat = { {0.1, 0.2 ... 0.6}, {0.2, 0.6, ...}, ...}
My problem is when I load data in python with
import numpy as np
myarray = np.fromfile...

1

votes

0

answer

31

Views

### Convolve many functions

I have a list of real functions:
T = {f1, f2, ..., fn};
(* For example it can be: *)
F[n_] := Function[x, Exp[-n Abs[x]]];
T = Table[F[n], {n, 10}];
and I would like to find the convolution of all of them.
Mathematica provides function Convolve, but this works for two functions and has rather weird...

1

votes

1

answer

37

Views

### How to create chart of decomposition data to categories?

I looking for programs or libraries that allow to create graphics presented below:
Idea is the following:
W have some initial value
It is divided to different states
These divisions can occur some times
We want to present name and value connected with each state
Is is possible to generate such image...

1

votes

0

answer

9

Views

### Wolfram Mathematica Solve command for a nonlinear system of equations

I am trying to solve a nonlinear system of equations by using the Solve (and NSolve) command, but the evaluation get stuck.
For a very similar system, basically the same but with the derivatives of the equations I get no problems. I define the functions I need, write the equations, define the variab...

1

votes

2

answer

113

Views

### How to use reverse Scaling function with error bars in mathematica?

I have data which I would like to plot along with the corresponding error bars:
{{{54927.7, -1.91044}, ErrorBar[38.2664, 0.0538982]},
{{55320.9, -1.97673}, ErrorBar[45.3592, 0.101486]},
{{55671.4, -2.15716}, ErrorBar[41.2234, 0.0258249]},
{{56032.9, -2.15957}, ErrorBar[38.8805, 0.0191277]},
{{56410....

1

votes

1

answer

50

Views

### Plot shows different answer for the similar arguments

I've just started to learn mathematica so forgive me if it's a simple question. I'm trying to find out why Plot that contains expression with ReplaceAll works different from Plot with Set . I have:
Clear['Global`*']
I0[t_] = HeavisidePi[(t - 1/2 10^-9)/10^-9];
sol = DSolve[{D[I2[t], t]*R == I1[t]/C0...

1

votes

1

answer

26

Views

### How to make many plots, with functions For and Plot?

I need to make several plots and i'm trying to do it with the help of For.
My data:
0.0023709,8.5752e-007,4.847e-008
My code:
column1 = data[[All,1]]
For[i = 1, i < 4, Plot[column1[[i]]*t, {t, 0, 10}]]
After running Mathematica write 'Running' and that's all.
I want make several plots for some lis...

1

votes

1

answer

60

Views

### Dynamic Manipulate function in Wolfram?

I am writing a demonstration for a digital GUI for analog filter design. Since demonstrations only allows for one Manipulate function, is there any way to dynamically update my Manipulate controls?
E.x. I have 4 different filter types (Lowpass, Highpass, Bandpass, Bandstop), the former two only requ...

1

votes

2

answer

55

Views

### Axes numbers interfere with each other

I have a plot in Mathematica, and the problem is: the axes numbers of plot interfere with each other. How can I eliminate the middle numbers, For example, '5*10^12, 5*10^13, ...' and keep the main numbers '1*10^12, 1*10^13, ...'. is there any other way to solve the problem?
Plot

1

votes

0

answer

55

Views

### how to improve the performance of this recursion code in mathematica

Clear[r, re, p, pmax, delta, imagesize, delta]
ClearSystemCache[]
re[0, r_] := Sqrt[8/Pi]*((1 - r)/r)^(1/4)*1;
re[1, r_] := Sqrt[8/Pi]*((1 - r)/r)^(1/4)*-1*2*(1 - 2*r);
re[p_, r_] := re[p, r] = Sqrt[8/Pi]*((1 - r)/r)^(1/4)*(-1)^p*(re[1, r]*re[p - 1, r] - re[p - 2, r]);
imagesize = 32;
pmax = 10;...

1

votes

0

answer

52

Views

### Can I get AST for wolfram language expressions?

In Mathematica, we use FullForm or TreeForm or Developer'WriteExpressionJSONString to get the syntax details for given expressions. How can I get a complete AST (Abstract Syntax Tree) for any expression? For example, is there any function toAST such that
toAST['a +b c\nSin[%];']
which will give the...

1

votes

0

answer

34

Views

### Maximum log-likelihood from data histogram not data directly

I have a complicated theoretical Probability Density Function (PDF) that I define in mathematica and that depends on some parameters that I need to estimate from comparison with real data. From a big simulation done on a cluster and not my laptop I have acquired a lot of events (over 10^9).
The wa...

1

votes

0

answer

31

Views

### Analytic Solution for ODE

I HAVE EQUATION
y - 7(e^x/x)dydx=0
How to find analytic solution in Mathematica?
My work :
I simplify the equations become y'=yx/7e^x
I run in Mathematica,
DSolve[y'[x] == (y[x] x)/(7 e^x), y[x], x]
I get result:
{{y[x] -> E^(1/7 E^-x (-1 - x)) C[1]}}.
Questions:
Are my simplifications correct?
D...

1

votes

1

answer

62

Views

### Mathematica In[1]/Out[1]

I am a new Mathematica user. I have a simple question: Every time I open a new Mathematica notebook the input entry number does not start from In[1] but follows from the number of the last input in the last Mathematica notebook I work. It follows each variable I assign in one notebook will pass auto...

1

votes

0

answer

49

Views

### Executing Wolframscript Code in Rstudio Through Terminal

I am interested in using Wolframscript to perform certain operations in R but am a bit new to programming at a level beyond data analytics.
It is rather easy to start a terminal running wolframscript:
rstudioapi::terminalExecute('wolframscript')
will open it in a terminal tab. Indeed, one can also r...

1

votes

1

answer

25

Views

### Eventhandler won't let me select graphic when MouseClicked is assigned

I'm trying to digitize points in an image and I would like to use KeyDown events to clear selected points.
For the KeyDown to work the image must be selected by clicking it (orange border shows around the image).
When the MouseClicked is assigned it will register the point in my image, but the image...

1

votes

1

answer

30

Views

### How to define symbolic time series/ sequences?

I need to check some equations involving operations on infinite length time series / sequences.
Say that I want to check the equation below:
I would like to define a time series filled with symbolic entries:
Later on, I would define X[n] and then check the first equation.
Is this doable? If so, how...

1

votes

1

answer

46

Views

### 3D plot from 1×n(one column) vector

I want to Plot 3D figure from a 1×n(column vector) containing numeric data. I have used ListPlot3D but its not working as I need to convert 1×n(column vector) vector into n×n matrix first then I can use the command
ListPlot3D[{{x1,y1,z1},{x2,y2,z2},…}]
Please guide me how I can convert first 1...

1

votes

0

answer

46

Views

### The font weight of output pdf plots from Mathematica 11.3

I am using Mathematica for plotting. The current version is 11.3. When I output vector figures such as .pdf and .eps formats, the font weight of the tick labels and text become bold, even though I set as plain text. Does anybody have the same problem? Could you help me to solve this? Thank you in ad...

1

votes

1

answer

36

Views

### Using Mathematica to solve this differential equation

I want to describe the kinetics of a chemical reaction and my idea of a reaction model results (simplified) in a differential equation of the following form:
y1'(t)=y1(t)+y2(t)
where y1 is the from an experiment measured concentration of a reactant and y2 the measured concentration of a product over...

1

votes

1

answer

50

Views

### Fitting parameter b of the Gamma distribution from mean, 95% in Python

This Mathematica function finds parameter b of the Gamma distribution,
given mean and 95% values and scaled by the mean [Mu];
The two values bracket [Beta] makes it fast and there is a restriction for max pg95= 5.8[Mu]* gb[[Mu], p95].
I need to translate this code into Python:
gb[\[Mu]_, p95_] :=...

1

votes

1

answer

28

Views

### How to implement a function with Python(Sympy), realizing the same as ToExpression in Wolfram Mathematica?

In Wolfram Mathematica, I can use ToExpression to convert a string to an expression, and evaluate the expression.
An example:
Reflection[expr_, a_] := expr /. a[l_] -> I*a[-l]
StringA = 'Reflection[a[0]b[3],b]'
Output=ToExpression[StringA]
the result is ia[0]b[-3]
However, I don't know how to reali...

1

votes

0

answer

22

Views

### Is there any Python function to define the 'findroot function' of Wolfram Mathematica?

I am trying to rewrite some codes from Mathematica into Python. Is there a way to describe Findroot function in Python 3.x?
here is the code from wolfram mathematica!
[Mu]FindRoot[CDF[GammaDistribution[1/b, b], p] - .95 == 0, {b, 1, If[p == 1, 1.1, p]}][[1, 2]]]
#b is for beta

1

votes

1

answer

407

Views

### Weather Conditions in Mathematica

I have yet to find a city or location or date, that gives me an answer other than Missing[NotApplicable] to the following query.
WeatherData['Chicago', 'Conditions', {2010, 8}]
That syntax works for 'Temperature' and 'Pressure' and 'WindDirection' But not 'Conditions'. In particular, if you want da...

1

votes

1

answer

66

Views

### Something like $AssertFunction=Abort[];Message[]

I'd like to customize the new Assert to print message as it usually does, but to also Abort[] all computation. Abort[] part is easy, but how do I generate the same message as the default?

1

votes

1

answer

352

Views

### Mathematica: “15 digits of Sqrt[x] yield 42+ million digits of x”

I did this in Mathematica to compute Sqrt[5]:
a[0] = 2
a[n_] := a[n] = a[n-1] - (a[n-1]^2-5)/2/a[n-1]
How close is a[25] to Sqrt[5]?
N[Sqrt[5]-a[25]] // FortranForm
4.440892098500626e-16
And how close is a[25]^2 to 5?
N[a[25]^2-5] // FortranForm
8.305767102358763e-42074769
This seems odd to...