Structuring convoluted list to the form useful in ListPlot

From an excel file, I have the following form of the (raw) data:

{{x1, y11, y12, y13, y14}, {x2, y21, y22, y23, y24}, ..., {xn, yn1, yn2, yn3, yn4}} 

I want to make a ListPlot by considering points {xi, yij} for each i and j. The points with same j are to be joined by a line segment. Then, I should be able to manipulate the above list. How can I do this?

Does mathematica cache the interpolating function from ParametricNDSolve?

I want to evaluate the solution of a system of non-linear ODEs using ParametricNDSolve. The output of ParametricNDSolve is a ParametricFunction object. Let’s call it $ f_\theta(t)$ , where $ \theta$ is a list of all parameters used in ParametricNDSolve.

For a given choice of the parameters $ \hat\theta$ , the ParametricFunction becomes a InterpolatingFunction object. I want to evaluate this function at multiple points $ \{t_1,t_2,…,t_n\}$ , which is, obtaining the value $ f_{\hat\theta}(t_i)$ .

Does Mathematica fully solve the system of equations each time I call $ f_{\hat\theta}(t_i)$ for a different $ i$ ? Or does it cache the InterpolatingFunction after the first call (let’s say, $ f_{\hat\theta}(t_1)$ ) and uses it to obtain the value of $ f_{\hat\theta}$ at $ t_2,…,t_n$ ?

Solve Differential Equation with Boundary Conditions (lengthy equation)

I have a lengthy equation to be substitute into a differential equation. I used DSolve to generate the output. However, it took me more than 3 hours and it still running. The DE is the convective-diffusion equation which is

1/r del /del r (r del f1s/ del r) - a1 = 0

and the boundary condition is r=k when del f1s/ del r =0

so the input is:

a1 = -(810165067720210957064125/25546163167349695028752149) -       0.00395833 (-0.5 + r) (1.02817 +          3.98107/(5.36839*10^11/r - 1.*10^12 r)^(1/20) +          2./((1.27718 - 0.666667 r - 0.333333 r^2)/(1. + r))^(1/20) +          3./((3.05377 - 0.888889 r - 0.111111 r^2)/(4. + r))^(1/20) +          3.01772/(-((1. (-0.675531 + 0.125 r + r^2))/(0.0625 + r)))^(         1/20) + 3.03794/(-((1. (-0.867019 + 0.285714 r + r^2))/(           0.142857 + r)))^(1/20) +          2.04096/(-((1. (-1.14539 + 0.5 r + r^2))/(0.25 + r)))^(1/20) +          3.08948/(-((1. (-1.57936 + 0.8 r + r^2))/(0.4 + r)))^(1/20) +          3.12414/(-((1. (-2.32712 + 1.25 r + r^2))/(0.625 + r)))^(1/20) +          3.23431/(-((1. (-7.80849 + 3.5 r + r^2))/(1.75 + r)))^(1/20)) +       0.125 (-0.5 + r) (0.196614 +          1.32702*10^-12 (5.36839*10^11/r - 1.*10^12 r)^(19/20) +          0.666667 ((1.27718 - 0.666667 r - 0.333333 r^2)/(1. + r))^(          19/20) + ((3.05377 - 0.888889 r - 0.111111 r^2)/(4. + r))^(         19/20) +          0.894139 (-((1. (-0.675531 + 0.125 r + r^2))/(0.0625 + r)))^(          19/20) +          0.787613 (-((1. (-0.867019 + 0.285714 r + r^2))/(0.142857 + r)))^(          19/20) +          0.453547 (-((1. (-1.14539 + 0.5 r + r^2))/(0.25 + r)))^(19/20) +          0.572125 (-((1. (-1.57936 + 0.8 r + r^2))/(0.4 + r)))^(19/20) +          0.462835 (-((1. (-2.32712 + 1.25 r + r^2))/(0.625 + r)))^(          19/20) +          0.239579 (-((1. (-7.80849 + 3.5 r + r^2))/(1.75 + r)))^(19/20))   TRY = DSolve[{1/r D[r f1s'[r], r] - a1 == 0, f1s'[k] == 0}, f1s, r, GeneratedParameters -> S] 

I’m stuck and I don’t know what else should I do. I tried to do manually by integrating the equation but it’s kinda haywire. Could anyone help me out with this coding. Really appreciate it 🙂

How to straighten a curve?

What’s the easiest way to get the following animation for a given parabola

enter image description here

My main goal is the following, given a set of random points and a set of points following a parabola, I want to "straighten" the parabola and all the surrounding points according to the straightening of that parabola. Consider the following schematic

enter image description here

For instance, we could consider the points as a starter

f[x_, a_, b_] := a x^2 + b; pts1 = RandomReal[{-1, 1}, {150, 2}]; ptsf = RandomReal[{-1, 1}, 50]; pts2 = Map[{#, f[#, .5, -.5]} &, ptsf]; Graphics[{Gray, Point /@ pts1, Red, Point /@ pts2}] 

enter image description here

Where the red dots follow a parabola. How do change pts1 based on a and b? From such a pattern, I’d expect, after the transformation, to get something like

enter image description here

where the dots are sparser above the line and denser below it. I tried to make it work by using preservation of the arc length somehow, but it’s too slow.

Steam plotting of vector field showing empty output

I am trying to plot the stream lines for a vector field function, whose definition is exported to the wdx file uploaded here. The following simple code returns an empty plot:

ReadyFieldXY =  Import["C:\ReadyFieldXY.wdx"]; a0 = 0.00055; StreamPlot[Abs[ReadyFieldXY], {x, -a0/2, a0/2}, {y, -a0/2, a0/2}] 

enter image description here

I am not sure what is wrong here. Any suggestions would be appreciated.

How to compute eigenvalues of linear function (not matrix)?

How to compute eigenvalues of a known linear function? In Julia, there is a package https://jutho.github.io/LinearMaps.jl/dev/ to compute the matrix representation of given function, then we can compute eigenvalues of the final matrix.

And in MATLAB, function eigs can also directly compute eigenvalues of a linear function.

     d = eigs(Afun,n,___) specifies a function handle Afun instead of a matrix. The second input n gives the size of matrix A used in Afun. You can optionally specify B, k, sigma, opts, or name-value pairs as additional input arguments. 

enter image description here So how to realize them in Mma? This is my approach:

LinearMapMatrix[map_Association, dimension_] :=   Module[{vectorin, linearfunction, transformmatrix},    vectorin = Normal[map][[1, 1]]; linearfunction = map[vectorin];    transformmatrix =     Transpose[ParallelMap[linearfunction, IdentityMatrix[dimension]]]   ] 

But it costs a lot of Ram. If I want a matrix representation with huge dimension, this function would burn down the running notebook. Are there some better methods?

Determining the voltage ripple when the transient is over (mistake in result)

Well, I have the following code:

Clear["Global`*"]; u = 5; \[Tau] = (1/2)*10^(-3); c = 10^(-6); r = 1000; y = u*Sum[((1 - E^((-t + \[Tau] + 4 n \[Tau])/(c*r)))  HeavisideTheta[         t - 4 n \[Tau]] HeavisideTheta[         t - \[Tau] - 4 n \[Tau]]) - ((1 - E^((-t + (3 + 4 n) \[Tau])/(          c*r))) HeavisideTheta[t - 4 n \[Tau]] HeavisideTheta[         t - (3 + 4 n) \[Tau]]), {n, 0, Infinity}]; 

And I want to find the ripple in the voltage given by y when the transient part of that function is over. I can do that by finding the period time of that function and I found that I can use:

$ $ \lim_{\text{k}\to\infty}\left|\text{y}\left(\left(2\text{k}+3\right)\tau\right)-\text{y}\left(\left(2\text{k}+1\right)\tau\right)\right|\tag1$ $

Programming that in Mathematica, gives the following code:

FullSimplify[  Limit[Abs[(y /. t -> (2*k + 3)*\[Tau]) - (y /.        t -> (2*k + 1)*\[Tau])], k -> Infinity]] 

And Mathematica returns:

Interval[{0, 20}] 

Which is wrong, because it must return (I know that that is the good answer):

$ $ \frac{5 (e-1)}{1+e}\approx2.31059\tag2$ $

Where is my mistake, is it a coding mistake? Or a mathematical mistake? Thanks for any help.

Solving an equation over the integers

Consider the problem of finding all values of $ n \in \mathbb{N}$ s.t. $ $ \sqrt{n} + \sqrt{n + 2005}$ $

is an integer.

One can easily verify that $ n = 1,004,004$ and $ 39,204$ satisfy this requirement, and in fact are the only such solution values for $ n$ . The simplest approach is to set the right hand side to some variable $ m \in \mathbb{Z}$ , square both sides, manipulate and note the prime factorization of $ 2005$ … that is, $ 2005 = 2005 \cdot 1 = 401 \cdot 5$ and equate factors.

I would like to compute the solution directly, however.

The natural approaches do not work:

Solve[  Sqrt[n] + Sqrt[n + 2005] == m, {n, m}, Integers] 

and

FindInstance[  Sqrt[n] + Sqrt[n + 2005] == m , {n, m}, Integers] 

and

Assuming[{n, m} \[Element] Integers,  Solve[Sqrt[n] + Sqrt[n + 2005] == m, {n, m}]] 

I’ve tried a number of minor variations, adding constraints such as $ \{ n, m \} > 0$ , and so forth. None work.

As yarchik shows (below), one can solve this with the result from number theory that each of the component square roots must resolve to an integer (demonstrated here). That leads to two questions:

  • What would we do if we didn’t know that fact from number theory?
  • Supposing we do know that fact from number theory. How would we programmatically impose it as some form of constraint or subsidiary equation rather than "by hand"?

Suggestions?

Calculating Residue with NIntegrate fails

Trying to answer this interesting question Principal value from two different axis I observed a problem using Nintegrate:

The function func[p_] := 1/(Sinh[p/2] Sqrt[Cosh[p]]) has a pol at p==0.

The residue of this point evaluates to

Residue[func[z], {z, 0}] (*2*) Limit[func[z] z, z -> 0] (*2*) 

The result might be confirmed by integrating along a path in the complex plane which contains the pol. For example integrating along a square path

NIntegrate[func[z], {z, 1, I, -1, -I, 1}]/(2 Pi I) (*2*) 

evaluates correct value , whereas integrating along a circle

NIntegrate[func[ Exp[I \[CurlyPhi] ]]/(2 Pi I), {\[CurlyPhi], 0, 2 Pi}]  (*~0*) 

gives a message NIntegrate failed to converge... and a wrong result 0!

What’s wrong with this last integration?

How to modify to get the correct result?

Thanks!

Creating new variable names, Symbol or ToExpression

One can create new variable names by Symbol :

In[1]  Table[Symbol["x"<>ToString[i]], {i,1,5}] Out[1]  {x1,x2,x3,x4,x5} 

But it is also possible to use ToExpression (old firend) :

In[2]  Table[ToExpression["x"<>ToString[i]], {i,1,5}] Out[2]  {x1,x2,x3,x4,x5} 

There is a difference : Symbol will produce an error for incorrect varialbe names while ToExpression will do something meaningful.

In[3]  Table[Symbol[ToString[i]<>"x"], {i,1,5}] Out[3]  (* some error message with non-helpful output)  In[4]  Table[ToExpression[ToString[i]<>"x"], {i,1,5}] Out[4]  {x,2x,3x,4x,5x} 

Other than this, I see there is no difference. Is there a situation such that Symbol is more useful than ToExpression ?