mmal
  • Member for 9 years, 7 months
  • Last seen more than a month ago
5 answers
5 votes
264 views
Rearrange graph
Accepted answer
10 votes

You can use MapAt function to map function on specific part of the expression MapAt[f, {1 -> 2, 2 -> 3, 3 -> 1}, {All, 2}] (* ==> {1 -> f[2], 2 -> f[3], 3 -> f[1]} *) or use ...

View answer
1 answers
3 votes
2k views
A basic problem with Solve
Accepted answer
9 votes

You should use the SolveAlways function, which will solve your equation for all values of the parameters (in this case for any t). So the solution to your question is SolveAlways[4 b*Cos[2 t] - 4 a*...

View answer
4 answers
4 votes
194 views
Numeric range: present or not
8 votes

IntervalMemberQ[Interval[{-2, 6}], 3] (* => True *)

View answer
2 answers
5 votes
216 views
Non-convergence of the solution of the 1+1 partial differential equation
Accepted answer
7 votes

Actualy, for $a=1/5$ the solution converges. The convergence speed for relaxation process is sensitive to initial condition, and greately slows down near fixed point solution. Using default options ...

View answer
6 answers
11 votes
553 views
Performing Computations on Sets
7 votes

A brute force solution is to check all possible values of this function. num = {1/10, 1/2, 4/7, 3/5, 2/3}; pow = {0, 1, 2, 3, 4}; To obtain value for one combination use the Inner function Inner[...

View answer
1 answers
2 votes
236 views
FiniteDifferenceDerivative of complex function in 2D--bug?
Accepted answer
6 votes

This is clearly a bug in 10.0 up to 10.2. According to reply to my report [CASE:3484187] The issue has been resolved in version 10.3. Please upgrade. I hope this will be helpful to someone.

View answer
3 answers
2 votes
355 views
How to iteratively integrate a function and sum the result of each iteration
6 votes

Try NestList[Integrate[#, x] &, x, 2] // Rest // Accumulate to get the list of successive iterations or NestList[Integrate[#, x] &, x, 2] // Rest // Total to obtain only the last element.

View answer
1 answers
1 votes
302 views
Manipulate doesn't work for plotting a region where a matrix is positive semi-definite
Accepted answer
6 votes

Try to define your matrix as a function of $(x,q,r,t)$ variables S[x_, q_, r_, t_] := {{1/r^2, 1, 1, t Sqrt[x]}, {1, 1/t^2, 1, Sqrt[x]/t}, {1, 1, 1, Sqrt[q]}, {t Sqrt[x], Sqrt[x]/t, Sqrt[q], 1}}; ...

View answer
1 answers
4 votes
439 views
My mistake or error in NDSolve?
6 votes

Your theoretical arguments are correct. The reason for this spurious oscillations is the numerical error. If you increase error tolerance in NDSolve (note that default tolerance is $\sim 10^{-7}$) you ...

View answer
3 answers
6 votes
3k views
Solution of equation with power series (perturbation)
6 votes

Let define the equation to solve $f=x-y\epsilon\sin(2 x)\equiv 0$ and series expansion of $y$ in powers of $\varepsilon$. f = x - y - \[Epsilon] Sin[2 y]; ord = 3; y = x + Sum[a[n] \[Epsilon]^n, {n, ...

View answer
2 answers
4 votes
1k views
Finding terms of the perturbation solution
Accepted answer
5 votes

You may start with something like that equ = {-y'[t] + 1 + (1 + \[Epsilon]) y[t]^2}; y[t_] := Sum[x[i][t] \[Epsilon]^i, {i, 0, 10}] // Evaluate; First order solution (use SeriesCoefficient function ...

View answer
1 answers
1 votes
169 views
Export data from NDSolve when they meet a certain condition
Accepted answer
5 votes

Even if there is some kind of mistake (typo) the solution is to use WhenEvent with Sow and Reap: {sol, {pts}} = Reap@NDSolve[{x''[t] == x[t]/(2*Sqrt[x[t]^2 + (1 - y[t])^2]), y''[t] == -0.2 - ...

View answer
2 answers
5 votes
1k views
How to graph a series of coupled oscillators and watch the wave move along them
5 votes

Solution by @Kuba can be easily extended to put the oscillators on a circle. Loin = NDSolve[Stew, Table[x[i], {i, 0, 10}], {t, 50}]; fr[t_] = Transpose@{Most@Range[0, 2 Pi, 2 Pi/11], x[#][t]&/@...

View answer
1 answers
2 votes
648 views
Problem with Sinc[x] function and rounding
Accepted answer
5 votes

The problem in your question is not about accuracy of $\text{sinc}(x)$ function itself but with the precision of FindRoot. When you increase working precision of the calculations (by using ...

View answer
2 answers
1 votes
140 views
depicting specific element of a table (knowing its position) in different color
4 votes

For better presentation I've decreased size of matrices to 4. n = 4; MatrixForm[m = Array[Subscript[a, ##] &, {n, n}]] With[{ij = {RandomInteger[{1, n}], RandomInteger[{1, n}]}}, ReplacePart[m,...

View answer
1 answers
3 votes
430 views
DensityPlot with the same color scale in Show
4 votes

You should have a look at ColorFunctionScaling option. When set to False in your case it gives Show[ DensityPlot[x^2 + y^2, {x, 0, 1}, {y, -1, 1}, PlotRange -> {0, 2}, ...

View answer
2 answers
4 votes
77 views
Type error before replacement rule is applied
Accepted answer
4 votes

Use one of the following a <> "0" /. {a -> "1"} // Quiet or ReleaseHold[Hold[a <> "0"] /. {a -> "1"}]

View answer
1 answers
5 votes
572 views
WhenEvent method with 3 conditions
Accepted answer
4 votes

You can use Piecewise function in the definition of DE. So for system at hand the NDSolve command would be xyz = First@ NDSolve[{x''[t] == -2.25 Cos[1.5 t] - x[t] - x'[t], x[0] == 0, x'[0] == ...

View answer
1 answers
5 votes
2k views
How can I plot the real and imaginary parts of a complex function given by an implicit equation?
Accepted answer
4 votes

First, I would suggest simplifying your equation. For this I've converted all constants to exact numbers q1 = 1; q2 = 1/2; e1 = 1; e2 = 8/10; s1 = 1; s2 = 6/10; γ = 1000; m1 = Sqrt[ζ^2 - I*w/s1]; m2 =...

View answer
2 answers
2 votes
432 views
local variable naming & symbolic argument
4 votes

You can not assign to a list in local variable specification as You did {x1,x2,sd1}=measure. You can assign specific parts of dummy variables: AntennaPower[measure_, antenna_] := Module[{x1=measure[...

View answer
2 answers
1 votes
473 views
ParametricNDSolve and NDSolve inside Manipulate environment
3 votes

I would recommend to code intermediate steps as separate functions, e.g. solve[a_?NumericQ] := z /. First@ NDSolve[{x'[t] == (x[t]*a*(x[t] + y[t] + z[t]))/(a*x[t] + 2.13*y[t] + 2.34*z[t]) - x[t],...

View answer
1 answers
4 votes
470 views
How to demonstrate lack of stability with advection equation
Accepted answer
3 votes

Forcing large enough constant step size (in time) for NDSolve method lead to instabilitity. sol = NDSolve[{D[u[t, x], t] == 0.5 D[u[t, x], x, x] + u[t, x] D[u[t, x], x], u[t, -Pi] == u[t, Pi] == ...

View answer
1 answers
2 votes
227 views
Replace inverse function
Accepted answer
3 votes

You need to replace function u with your definition, not only the u[x] symbol. Defining u as a function solves the problem Solve[u[x] == u[a] + u[b], x] /. {u -> Function[x, x]} (* ==> {{x -&...

View answer
4 answers
1 votes
194 views
Data format of Date including data
3 votes

You can use the pattern matching as @Sjoerd C. de Vries suggested, eg. Cases[data, {d_, v_} :> {d[[1 ;; 3]], v}] or Cases[data, {{y_, m_, d_, ___}, v_} :> {{y, m, d}, v}] Alternately you can ...

View answer
3 answers
6 votes
314 views
Why is NDSolve's StartingStepSize with ExplicitEuler not working? How do I set the step size?
2 votes

I would suggest (as an alternative) the following pointsAndValues[x_InterpolatingFunction] := Transpose[{First[x["Coordinates"]], x["ValuesOnGrid"]}]; ListPlot[ pointsAndValues@ First@...

View answer
1 answers
6 votes
759 views
Preconditioning the objective function of NIntegrate for higher PrecisionGoal
Accepted answer
2 votes

Maybe the solution would be to forget about NIntegrate and to try to do it 'by hand', e.g. integrate[f_, nx_, prec_: MachinePrecision] := Module[{xg, fg}, xg = Table[(2 i - 1)/(2*nx) \[Pi], {i, 1, ...

View answer
2 answers
0 votes
3k views
How to get a number from Solve
2 votes

Just extract second argument from Rule function by Solve[p == 2 t + 1, t][[1, All, 2]] Use All in case of more then one solution.

View answer
2 answers
1 votes
3k views
Contour plot of complex function: problem in choosing argument
2 votes

What about the following: F[x_, y_] := Sin[Sin[x - y]] + I Cos[Cos[x + y]]; With[{x = a - 3 I}, ContourPlot[{Re[F[x, y]] == 0, Im[F[x, y]] == 0}, {a, -1, 1}, {y, -3/2, 3/2}, FrameLabel -> (...

View answer
2 answers
1 votes
234 views
How to use NMinimize with a large scale of variables?
1 votes

I would try to use: Module[{x = x, n = 12, vars}, vars = ToExpression[ToString[x] <> ToString[#]] & /@ Range[n]; NMinimize[ Flatten@{GoalFunction[graph, vars], cons[graph, vars, 2500], ...

View answer
1 answers
1 votes
161 views
Estimating error in NDSolve
Accepted answer
1 votes

See this to find out the method used by NDSolve and this sol = NDSolveValue[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]; Differences @ First @ sol["Coordinates"] to get magnitude of ...

View answer