Newest questions tagged variable - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-21T14:11:56Z https://mathematica.stackexchange.com/feeds/tag?tagnames=variable&sort=newest https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/203866 0 remove one of the column in the output of Solve command asad https://mathematica.stackexchange.com/users/18811 2019-08-17T13:24:45Z 2019-08-17T16:04:49Z <p>I would like to remove one variable in the output of the "Solve" command without changing the rest. For instance, in the following code</p> <pre><code>p = 6; A = Solve[{p == x + y + z + t &amp;&amp; x &gt; 0 &amp;&amp; y &gt;= x &amp;&amp; z &gt;= y &amp;&amp; t &gt; 0}, {x, y, z, t}, Integers] </code></pre> <p>we have the output</p> <pre><code>{x -&gt; 1, y -&gt; 1, z -&gt; 1, t -&gt; 3},{x -&gt; 1, y -&gt; 1, z -&gt; 2, t -&gt; 2},{x -&gt; 1, y -&gt; 1, z -&gt; 3, t -&gt; 1},{x -&gt; 1, y -&gt; 2, z -&gt; 2, t -&gt; 1} </code></pre> <p>and I need to remove for example the last column for "t" and have:</p> <pre><code>{x -&gt; 1, y -&gt; 1, z -&gt; 1},{x -&gt; 1, y -&gt; 1, z -&gt; 2},{x -&gt; 1, y -&gt; 1, z -&gt; 3},{x -&gt; 1, y -&gt; 2, z -&gt; 2} </code></pre> <p>without changing the code in the input, I mean, I only want this change in the output section keeping the original output there.</p> https://mathematica.stackexchange.com/q/203477 3 From f[g[x,t]] to f[g] J.A https://mathematica.stackexchange.com/users/58104 2019-08-08T14:04:01Z 2019-08-08T14:43:58Z <p>How can you change </p> <pre><code>f[g[x,t],t] </code></pre> <p>to</p> <pre><code>f[g,t] </code></pre> <p>?</p> <p>I have differential equations</p> <pre><code>Derivative[1,0][f][g[x,t],t]== f[g[x,t],t]*t+Derivative[2,0]f[g[x,t],t] </code></pre> <p>And </p> <pre><code>f'[g[x,t]]== f[g[x,t]]*t+f''[g[x,t]] </code></pre> <p>And I'd like to use DSolve with <span class="math-container">$g$</span> as an independant variable, meaning : </p> <pre><code>DSolve[Derivative[1,0][f][g,t]== f[g,t]*t+Derivative[2,0]f[g,t],f,{g,t}] </code></pre> <p>I tried : </p> <pre><code>(f'[g[x,t]]== f[g[x,t]]*t+f''[g[x,t]])/.g[x,t]-&gt; g </code></pre> <p>but it failed</p> https://mathematica.stackexchange.com/q/203353 4 Computing Higher Order Tensor of Variable Rank Pentaquark https://mathematica.stackexchange.com/users/66857 2019-08-06T08:50:29Z 2019-09-05T16:02:05Z <p>The following code takes a vector <code>x</code> of variable length, computes the outer product of the vector with itself to form the matrix <span class="math-container">$\rho$</span> of dimension <span class="math-container">$2^n \times 2^n$</span>. The function <code>T[i_, list_List]</code> then computes elements of a tensor <span class="math-container">$\mathcal{T}$</span> of rank <span class="math-container">$n$</span> according to </p> <p><span class="math-container">$$T_{\mu_1,...,\mu_n}=\text{Tr}(\rho \;\; \sigma_{\mu_1}\otimes...\otimes\sigma_{\mu_n})$$</span></p> <p>with <span class="math-container">$\mu_1,...,\mu_n=1,2,3$</span> and <span class="math-container">$\sigma_i$</span> being the three Pauli Matrices. </p> <pre><code>OuterVectorProduct[x_] := KroneckerProduct[x, x] </code></pre> <pre><code>T[i_, list_List] := FullSimplify[Tr[i.KroneckerProduct @@ PauliMatrix[list]]] </code></pre> <p>That is: <code>T[rho,{1,1}]</code>outputs the <span class="math-container">$T_{11}$</span> element of the Tensor <span class="math-container">$\mathcal T$</span> with respect to some matrix <span class="math-container">$\rho$</span>. </p> <p>I would now like to write a function that outputs the entire tensor. To do so, I need to extract the number of arguments within the list in the function <code>T[i_,list_List]</code>.</p> <p>That is, in our example <code>T[rho,{1,1}]</code>, I need to extract the number of arguments in the curly braces. </p> <p>How does one do that? </p> <p>Thanks!</p> https://mathematica.stackexchange.com/q/203249 0 Functions with Variable Numbers of Arguments: Outer Vector Product Pentaquark https://mathematica.stackexchange.com/users/66857 2019-08-04T12:24:36Z 2019-08-04T13:18:50Z <p>I am trying to write a function that takes a column vector of variable dimension as an input and returns the outer product matrix as an output. </p> <p>What I have tried:</p> <pre><code>OuterVectorProduct[x__] := MatrixForm[Outer[Times, x, x]] </code></pre> <p>However, this obviously returns wrong results. </p> <p>Thanks!</p> https://mathematica.stackexchange.com/q/203229 5 How to transform a function from f[#1] to f[x] J.A https://mathematica.stackexchange.com/users/58104 2019-08-03T23:06:39Z 2019-08-05T09:52:11Z <p>So I have this function :</p> <pre><code>Sqrt[-1 + Tanh[#1 - #2]^2] &amp; </code></pre> <p>How can I transform it into </p> <pre><code>f[x_,y_]=Sqrt[-1 + Tanh[x - y]^2] </code></pre> <p>I tried </p> <pre><code>Sqrt[-1 + Tanh[#1 - #2]^2] &amp;/. #1 -&gt; x /. #2 -&gt; y /. &amp; -&gt; 1 </code></pre> <p>But apparently /. &amp; -> 1 doesn't work</p> https://mathematica.stackexchange.com/q/203084 3 General::ivar 0 is not a valid variable when using Series in Plot Oliver Murfett https://mathematica.stackexchange.com/users/66808 2019-08-01T05:29:22Z 2019-08-02T09:38:55Z <p>I have been having some trouble graphing a <em>Taylor</em> series approximation (<a href="https://reference.wolfram.com/language/ref/Series.html" rel="nofollow noreferrer"><code>Series</code></a>). </p> <pre><code>f[x] := Series[E^(-x/4) Sin[3 * x], {x, 1, 4}] Plot[f[x], {x, 0, 6}] </code></pre> <blockquote> <p>General::ivar: 0.00012257142857142857` is not a valid variable.</p> </blockquote> <p><a href="https://i.stack.imgur.com/GSBeH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GSBeH.png" alt="enter image description here"></a></p> <p><strong>How can I fix this error?</strong></p> https://mathematica.stackexchange.com/q/202913 5 Make assumption for function with variable argument sdnnds https://mathematica.stackexchange.com/users/30700 2019-07-29T09:45:30Z 2019-07-29T15:17:39Z <p>I would like to assume that <code>a&gt;t[b_]</code> for any <code>b</code>, such that e.g. <code>Simplify[a&gt;t[c]]==True</code>. How could this be done? Simply including</p> <pre><code>$Assumptions = a &gt; t[_] </code></pre> <p>does not work. </p> <p>I only need to consider functions of one argument, e.g. <code>t[c]</code> rather than <code>t[c,d]</code>.</p> https://mathematica.stackexchange.com/q/201560 0 Saving variable inside Manipulate command Edwin Herrera https://mathematica.stackexchange.com/users/63846 2019-07-04T15:42:06Z 2019-07-04T17:20:22Z <p>I have been working in a plotter using "manipulate", I let the code below. However, I would like change between different kind of "options" that I will add them after, the problem is when I change to a different option, the equation is changed, after when I return to the first option selected, the equation is cleared. There is a way to save this "equation" variable? </p> <p>I tried saving the equation into another variable but I continue with issues when I change the option. </p> <pre><code>kappaX[ghXX_, x_, xmin_, xmax_, xlabel_] := Plot[ghXX, {x, xmin, xmax}, PlotLabel -&gt; HoldForm[ghXX]]; Panel[Manipulate[Dynamic[If[AllTrue[{uMin, uMax}, NumericQ], Switch[tabNumber, tab1,DynamicModule[{Vbb = Null}, Column[{Style["Equation"], InputField[Dynamic[Vbb], String], KappaFigE = Dynamic[kappaX[ToExpression[Vbb, TraditionalForm], xvarI, uMin, uMax, variablenameI]]}]], tab2, DynamicModule[{Vbb = 10 (xpar1 xvar1) - 2 xvar1}, Column[{Style["Equation"], InputField[Dynamic[Vbb]], KappaFigE = Dynamic[kappaX[Vbb, xvar1, uMin, uMax, variablenameI]]}]], tab3, DynamicModule[{Vbb = 10 (xpar1 xvar1) + 10 xvar1 + xpar2}, Column[{Style["Equation"], InputField[Dynamic[Vbb]], KappaFigE = Dynamic[kappaX[Vbb, xvar1, uMin, uMax, variablenameI]]}]]], Graphics[{}]]], Grid[{{Style["Input Data", "Title"], SpanFromLeft, SpanFromLeft}, {TabView[{ "Option 1" -&gt; Column[tabNumber = tab1; {Row[{"This is the option 1"}]}], "Option 2" -&gt; Column[tabNumber = tab2; {Row[{"This is the option 2"}]}], "Option 3" -&gt; Column[tabNumber = tab3; {Row[{"This is the option 3"}]}]}, Dynamic@tabNumber]}, {Control@{{variablename, Null, Style["Parameter name 1"]}, InputField[#, String] &amp;}, Control@{{xpar1, Null, Style["Value"]}, InputField[#, Number] &amp;}, Button[Style["Save", Bold, 12], ToExpression[variablename, StandardForm, Function[name, name = xpar1, HoldFirst]]]}, {Control@{{variablename2, Null, Style["Parameter name 2"]}, InputField[#, String] &amp;}, Control@{{xpar2, Null, Style["Value"]}, InputField[#, Number] &amp;}, Button[Style["Save", Bold, 12], ToExpression[variablename2, StandardForm, Function[name2, name2 = xpar2, HoldFirst]]]}, {Style[ "Input Variable Name"], Control@{{variablenameI, Null, Style["Variable name I"]}, InputField[#, String] &amp;}, Button[Style["Save", Bold, 12], ToExpression[variablenameI, StandardForm, Function[nameI, nameI = xvarI, HoldFirst]]]}, {Control@{{uMin, 10, Style["uMin"]}, InputField[#, Number] &amp;}, Control@{{uMax, 100, Style["uMax"]}, InputField[#, Number] &amp;}}}], {{tabNumber, 1}, None}, {{tab1, 1}, None}, {{tab2, 2}, None}, {{tab3, 3}, None}, ControlPlacement -&gt; Left, SaveDefinitions -&gt; True]] </code></pre> <p><a href="https://i.stack.imgur.com/qGUJX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qGUJX.png" alt="enter image description here"></a> <a href="https://i.stack.imgur.com/sfTIy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sfTIy.png" alt="enter image description here"></a> <a href="https://i.stack.imgur.com/YxbEa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YxbEa.png" alt="enter image description here"></a></p> https://mathematica.stackexchange.com/q/200937 2 How to read in and assign values from a txt file? TLona https://mathematica.stackexchange.com/users/66265 2019-06-24T15:26:40Z 2019-06-25T23:06:16Z <p>I have a text file that I would like to import into <em>Mathematica</em> - after searching around the internet, I can't seem to find any pages that explain how to do this:</p> <p>The text file containes these four lines:</p> <pre><code>10 1 2 3 4 5 6 7 8 1000 100 </code></pre> <p>In my Mathematica code, I want to assign:</p> <pre><code>a = 10 list1 = {1, 2, 3} list2 = {4, 5, 6, 7, 8} b = 1000 c = 100 </code></pre> <p>Is there a way to do this? I'm not very versed in <em>Mathematica</em> so any help will be appreciated, thank you so much in advance!</p> https://mathematica.stackexchange.com/q/200731 0 Table and FindRoot of a 2 variable function of x and t : cos(x + 3t) Brendan Darrer https://mathematica.stackexchange.com/users/59044 2019-06-20T19:13:36Z 2019-06-20T19:28:41Z <p>I am trying implement <code>mathematica</code> commands: <code>Table</code> and <code>FindRoot</code>, of a 2 variable function <code>cos(x + 3t)</code> to find all the <code>x</code> values where the cosine function meets the <code>x</code> axis, i.e. <code>cos(x + 3t) == 0</code>, and the times, <code>t</code>, when this happens. Can someone indicate how this can be accomplished, or if it is possible within <code>mathematica</code>?</p> <pre><code>xInit = 0; xmin = -4 Pi; xmax = 4 Pi; dx = 0.1; tmin = 0; tmax = 10; Astep[x_, t_] := Cos[x + 3 t] Union[Table[x /. FindRoot[Astep[x, t] == 0, {x, xInit, xmin, xmax}, {t, 0, tmin, tmax}], {xInit, xmin + dx, xmax - dx, dx}], SameTest -&gt; Equal] </code></pre> <p>The error messages are:</p> <pre><code>FindRoot::nveq: The number of equations does not match the number of variables in FindRoot[Astep[x,t]==0,{x,xInit,xmin,xmax},{t,0,tmin,tmax}]. ReplaceAll::reps: {FindRoot[Astep[x,t]==0,{x,xInit,xmin,xmax},{t,0,tmin,tmax}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. General::stop: Further output of FindRoot::nveq will be suppressed during this calculation. </code></pre> https://mathematica.stackexchange.com/q/200661 0 Problem with fitting J.A https://mathematica.stackexchange.com/users/58104 2019-06-19T17:10:00Z 2019-06-19T19:45:00Z <p>So I have a very simple question related to a simple topic, but also directly related to a fitting problem. I see that my question is related to <a href="https://mathematica.stackexchange.com/questions/84618/minimizing-using-indices-error-partpkspec1-the-expression-cannot-be-used-as">this question</a> but I don't manage to make the bridge between them.</p> <p>The basic question is how to make a function that would look like :</p> <pre><code>list = {{1, 2}, 2, {3, 4, 8, 12}, 4, {2, 2, 2, 2, 2}} F[x_] = list[[x]] </code></pre> <p>And I want to use it in the following context :</p> <pre><code>err[Vinitphi_?NumberQ, l_?NumberQ, nc_?NumberQ, tauC_?NumberQ, tauG_?NumberQ, D0_?NumberQ, k_] = With[{model = (Rad /. pfun)[Vinitphi, l, nc, tauC, tauG, D0]}, Norm[rad[[k]][[2 ;; Length[rad[[k]]], 2]] - model /@ rad[[k]][[2 ;; Length[rad[[k]]], 1]]]] fit = FindMinimum[{Sum[ err[Vinitphi/2^(i - 1), l, nc, tauC, tauG, D0, i], {i, 1, 6, 1}], 3*10^7 &lt; Vinitphi &lt; 9*10^7, 15 &lt; l &lt; 30, 0.05 &lt; tauC &lt; 0.5, 0.2 &lt; nc &lt; 0.8, 4*10^(10) &lt; D0 &lt; 2*10^(11)}, {{Vinitphi, 4.5*10^7}, {l, 25}, {nc, 0.5}, {tauC, 0.2}, {tauG, 30}, {D0, 6*10^(10)}}] </code></pre> <p>where I get the error :</p> <blockquote> <p>Part::pkspec1: The expression k cannot be used as a part specification.</p> </blockquote> <p>Could you help please ?</p> <p>I write in the following appendix the ParametricNDSolve I'm taking care of :</p> <p><strong>Appendix :</strong></p> <pre><code>rad={{{0., 117.705}, {3., 148.255}, {6., 176.81}, {9., 183.561}, {12., 197.419}, {15., 210.672}, {18., 211.152}, {21., 209.889}, {24., 207.741}, {27., 204.352}, {30., 201.79}, {33., 199.976}, {36., 199.04}, {39., 197.151}, {42., 197.584}, {45., 196.198}, {48., 195.153}, {51., 195.711}, {54., 194.088}, {57., 193.304}, {60., 192.474}, {63., 192.13}, {66., 192.877}, {69., 192.371}, {72., 192.657}, {75., 190.984}, {78., 190.685}, {81., 190.449}, {84., 189.83}, {87., 189.625}, {90., 194.855}, {93., 186.581}, {96., 184.735}, {99., 184.586}, {102., 183.505}, {105., 181.531}, {108., 179.925}, {111., 178.428}, {114., 176.164}, {117., 175.375}, {120., 174.782}, {123., 172.649}, {126., 170.454}, {129., 168.357}, {132., 168.04}, {135., 167.26}, {138., 165.657}, {141., 164.797}, {144., 163.705}, {147., 161.214}, {150., 160.5}, {153., 159.353}, {156., 157.873}, {159., 157.225}}, {{0., 51.7792}, {3., 80.825}, {6., 108.913}, {9., 121.147}, {12., 130.805}, {15., 140.562}, {18., 143.615}, {21., 146.513}, {24., 147.63}, {27., 147.12}, {30., 146.693}, {33., 147.396}, {36., 148.256}, {39., 147.737}, {42., 148.685}, {45., 149.043}, {48., 147.814}, {51., 148.776}, {54., 147.959}, {57., 147.775}, {60., 148.031}, {63., 148.284}, {66., 148.334}, {69., 148.521}, {72., 148.974}, {75., 146.562}, {78., 145.734}, {81., 145.177}, {84., 145.588}, {87., 144.949}, {90., 147.035}, {93., 141.755}, {96., 140.841}, {99., 139.94}, {102., 138.25}, {105., 136.508}, {108., 135.52}, {111., 133.758}, {114., 132.694}, {117., 131.744}, {120., 131.208}, {123., 130.292}, {126., 127.612}, {129., 126.981}, {132., 127.035}, {135., 125.198}, {138., 123.557}, {141., 123.946}, {144., 120.738}, {147., 119.875}, {150., 118.828}, {153., 118.162}, {156., 117.363}, {159., 116.712}}, {{0., 29.62}, {3., 53.1414}, {6., 67.2233}, {9., 82.5676}, {12., 83.5019}, {15., 92.3142}, {18., 98.9869}, {21., 102.557}, {24., 106.481}, {27., 107.188}, {30., 107.637}, {33., 108.415}, {36., 109.622}, {39., 110.593}, {42., 111.205}, {45., 111.396}, {48., 111.668}, {51., 114.126}, {54., 113.3}, {57., 114.27}, {60., 114.849}, {63., 110.808}, {66., 116.51}, {69., 118.796}, {72., 119.636}, {75., 118.02}, {78., 116.026}, {81., 116.767}, {84., 116.994}, {87., 119.169}, {90., 121.246}, {93., 116.291}, {96., 117.296}, {99., 117.72}, {102., 115.814}, {105., 114.76}, {108., 114.853}, {111., 113.886}, {114., 112.522}, {117., 112.109}, {120., 112.376}, {123., 110.998}, {126., 109.708}, {129., 108.926}, {132., 108.075}, {135., 107.182}, {138., 106.723}, {141., 106.562}, {144., 103.807}, {147., 102.798}, {150., 102.333}, {153., 101.633}, {156., 100.395}, {159., 99.889}}, {{0., 79.5768}, {3., 86.0729}, {6., 101.334}, {9., 103.158}, {12., 104.818}, {15., 104.534}, {18., 104.361}, {21., 105.568}, {24., 107.109}, {27., 105.042}, {30., 105.165}, {33., 107.669}, {36., 108.182}, {39., 108.549}, {42., 109.208}, {45., 109.714}, {48., 110.098}, {51., 110.481}, {54., 110.373}, {57., 110.563}, {60., 111.115}, {63., 111.766}, {66., 112.415}, {69., 113.322}, {72., 113.272}, {75., 113.95}, {78., 113.98}, {81., 114.017}, {84., 111.879}, {87., 114.706}, {90., 112.125}, {93., 109.696}, {96., 112.481}, {99., 109.528}, {102., 108.22}, {105., 108.112}, {108., 107.387}, {111., 106.369}, {114., 106.522}, {117., 105.678}, {120., 111.234}, {123., 109.391}, {126., 104.95}, {129., 109.079}, {132., 109.363}, {135., 100.807}, {138., 99.9696}, {141., 100.622}, {144., 99.789}, {147., 98.5068}, {150., 99.6161}, {153., 97.4872}, {156., 101.554}, {159., 101.406}}, {{0., 30.4597}, {3., 35.889}, {6., 45.7724}, {9., 54.0641}, {12., 56.851}, {15., 59.1402}, {18., 61.0664}, {21., 63.1851}, {24., 65.2428}, {27., 66.6239}, {30., 67.5882}, {33., 68.5353}, {36., 69.885}, {39., 71.1742}, {42., 72.485}, {45., 73.2793}, {48., 74.2798}, {51., 74.7271}, {54., 74.8248}, {57., 75.83}, {60., 76.1228}, {63., 77.5324}, {66., 76.4005}, {69., 77.5578}, {72., 80.4519}, {75., 80.1548}, {78., 80.1533}, {81., 79.2626}, {84., 79.6456}, {87., 79.5882}, {90., 78.9125}, {93., 77.5023}, {96., 80.9046}, {99., 78.125}, {102., 78.1087}, {105., 82.0064}, {108., 80.6066}, {111., 82.9245}, {114., 83.6384}, {117., 82.0775}, {120., 81.1198}, {123., 75.248}, {126., 78.1893}, {129., 72.6991}, {132., 72.683}, {135., 80.5139}, {138., 83.442}, {141., 81.0871}, {144., 80.1472}, {147., 79.3543}, {150., 79.0979}, {153., 79.0636}, {156., 78.3953}, {159., 77.2895}}, {{0., 27.5731}, {3., 27.4456}, {6., 37.2589}, {9., 40.9683}, {12., 43.2509}, {15., 44.3384}, {18., 46.5891}, {21., 48.0219}, {24., 49.6954}, {27., 51.1536}, {30., 51.7754}, {33., 53.2019}, {36., 54.9082}, {39., 55.9732}, {42., 57.3092}, {45., 58.6397}, {48., 58.9803}, {51., 58.6734}, {54., 60.6691}, {57., 61.3107}, {60., 62.1459}, {63., 63.2534}, {66., 64.1169}, {69., 64.7201}, {72., 65.4561}, {75., 65.7958}, {78., 65.9518}, {81., 66.9163}, {84., 67.5038}, {87., 64.925}, {90., 69.8176}, {93., 65.8334}, {96., 69.2665}, {99., 66.6777}, {102., 65.9855}, {105., 69.4403}, {108., 70.2052}, {111., 69.9442}, {114., 70.7562}, {117., 70.3714}, {120., 63.5385}, {123., 62.8021}, {126., 67.0399}, {129., 61.5096}, {132., 63.1028}, {135., 70.3602}, {138., 70.2032}, {141., 69.4146}, {144., 68.2243}, {147., 67.9524}, {150., 67.8477}, {153., 68.2036}, {156., 68.2165}, {159., 67.5863}}} eps = 1; phic = 0.85; v = 80 a = 0 phi0 = 0.63; L = 5000; nL0 = 1; pfun = ParametricNDSolve[{Derivative[V][ t] == -(( D0 (E^(-((L + t v)^2/(4 D0 t)))) (-L + t v) Vinitphi )/((D0 t)^( 3/2)*4*Sqrt[Pi]*phi0)) + ( 2 Vphi[t] (phic - Vphi[t]/V[t]) (-2 + phic + 2 (1 - Vphi[t]/V[t])) (1 - (1 - Vphi[t]/V[t])^2))/((1 - phic)^2 tauC V[t]^( 1/3)) - (-nc V[t] - ( 4 l L nL0 \[Pi] Csch[((E^(((a Vphi[t])/( 2 V[t])))) ((3/\[Pi])^(1/3)) (V[t]^(1/3)) )/( 2^(2/3) l)] (-E^(-((a Vphi[t])/V[t])) l^2 Sinh[((E^(((a Vphi[t])/(2 V[t])))) ((3/\[Pi])^( 1/3)) (V[t]^(1/3)) )/(2^(2/3) l)] + ( E^(-((a Vphi[t])/(2 V[t]))) l (3/\[Pi])^(1/3) Cosh[((E^(((a Vphi[t])/(2 V[t])))) ((3/\[Pi])^(1/3)) ( V[t]^(1/3)) )/(2^(2/3) l)] V[t]^(1/3))/(2^( 2/3)) ))/ (-L Coth[((E^(((a Vphi[t])/( 2 V[t])))) ((3/\[Pi])^(1/3)) (V[t]^(1/3)) )/( 2^(2/3) l)] + ((3/\[Pi])^(1/3) Coth[((E^(((a Vphi[t])/(2 V[t])))) ((3/\[Pi])^(1/3)) ( V[t]^(1/3)) )/(2^(2/3) l)] V[t]^(1/3))/2^(2/3) - l))/ tauG, V[eps] == 4*Pi/3*2^3, Derivative[Vphi][ t] == -((D0 (E^(-((L + t v)^2/(4 D0 t)))) (-L + t v) Vinitphi )/( 4*Sqrt[Pi]*phi0 (D0 t)^(3/2))) + (( Vphi[t] (-nc V[t] - ( 4 l L nL0 \[Pi] Csch[((E^(((a Vphi[t])/( 2 V[t])))) ((3/\[Pi])^(1/3)) (V[t]^(1/3)) )/( 2^(2/3) l)] (-E^(-((a Vphi[t])/V[t])) l^2 Sinh[((E^(((a Vphi[t])/(2 V[t])))) ((3/\[Pi])^( 1/3)) (V[t]^(1/3)) )/(2^(2/3) l)] + ( E^(-((a Vphi[t])/(2 V[t]))) l (3/\[Pi])^(1/3) Cosh[((E^(((a Vphi[t])/(2 V[t])))) ((3/\[Pi])^(1/3)) ( V[t]^(1/3)) )/(2^(2/3) l)] V[t]^(1/3))/(2^( 2/3)) ))/ (-L Coth[((E^(((a Vphi[t])/( 2 V[t])))) ((3/\[Pi])^(1/3)) (V[t]^(1/3)) )/( 2^(2/3) l)] + ((3/\[Pi])^(1/3) Coth[((E^(((a Vphi[t])/(2 V[t])))) ((3/\[Pi])^(1/3)) ( V[t]^(1/3)) )/(2^(2/3) l)] V[t]^(1/3))/2^(2/3) - l)))/ V[t]) /tauG, Vphi[eps] ==4*Pi/3*2^3*phi0, Rad'[t] == V'[t]/V[t]^(2/3)/(4*Pi/3)^(1/3), Rad[eps] == 2 }, {V, Vphi, Rad}, {t, eps, 170}, {Vinitphi, l, nc, tauC, tauG, D0}, Method -&gt; {"EquationSimplification" -&gt; "Residual"}] </code></pre> <p>You can check my initial guess is not too bad :</p> <p><a href="https://i.stack.imgur.com/lepDo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lepDo.png" alt="enter image description here"></a></p> https://mathematica.stackexchange.com/q/200267 1 How to express a function in terms of new variable? Kartik Chhajed https://mathematica.stackexchange.com/users/58974 2019-06-13T05:11:30Z 2019-06-13T09:10:52Z <p>I have </p> <pre><code>In:= g[a_, x_, y_] = Simplify[Limit[f4[t], t -&gt; Infinity]] + Sqrt[-1]*Simplify[Limit[f5[t], t -&gt; Infinity]] Out= ConditionalExpression[(1 + a + a x + a^2 x - a y)/( 3 + 3 a + a^2) + (I (1 + a x + 2 a y + a^2 y))/( 3 + 3 a + a^2), (x | y) \[Element] Reals &amp;&amp; a &gt; 0] </code></pre> <p>Now I want to express the <code>g[t,z]</code> in terms of a new variable</p> <pre><code>z = x + Sqrt[-1] y; </code></pre> <p>I was looking for expression like this <img src="https://i.stack.imgur.com/bt60L.jpg" alt=""></p> https://mathematica.stackexchange.com/q/200175 0 Five equations to solve 6-variables question, is it possible? Azlan https://mathematica.stackexchange.com/users/66079 2019-06-12T01:22:32Z 2019-06-12T03:29:57Z <p>I was given a task to find the value of variable a,b,c,d,e and f. But I'm not sure it is even possible, given that only 5 equations are available. Can anybody point out how to solve these:</p> <pre><code>a+b+c=164.35; d+e+f=94.44; a^2+d^2=20.06^2; b^2+e^2=74.34^2; c^2+f^2=123.27^2 </code></pre> <p>Thank you.</p> https://mathematica.stackexchange.com/q/199822 1 How to use a table with two variables as the values for a function with two variables (x and y)? [duplicate] missalyssa https://mathematica.stackexchange.com/users/65986 2019-06-05T23:36:05Z 2019-06-06T08:33:20Z <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/1970/using-sets-of-arguments-from-a-list" dir="ltr">Using sets of arguments from a list</a> <span class="question-originals-answer-count"> 3 answers </span> </li> </ul> </div> <p>I'm sorry if this is a dumb question. I am a student and have 0 prior experience with Mathematica or any sort of coding and I have looked at various resources trying to figure it out myself but still need help. Also, I'm sorry if anything is confusing.</p> <p>This is my function. The virus[vt] and Sigma parameters are set.</p> <pre><code>Fitness1[x_, y_] := Exp[-((x + y)/2 - (virus[vt]))^2/(2 \[Sigma]^2)] </code></pre> <p>This is my table.</p> <pre><code>GenotypesMale1 = Table[{Random[NormalDistribution[2, \[Sigma]m]], Random[NormalDistribution[2, \[Sigma]m]]}, {20]}] </code></pre> <p>The output of the Table function above is</p> <pre><code>{{1.62001, 2.40024}, {2.18355, 2.60117}, {1.83962, 2.709}, {1.94572, 2.37221}, {1.69635, 1.30685}, {2.35385, 2.24577}, {1.84914, 3.01337}, {2.01219, 2.47033}, {1.36143, 2.75167}, {2.54443, 2.46801}, {1.89521, 1.12607}, {1.1986, 1.74052}, {2.45004, 1.72624}, {2.35641, 1.98379}, {1.48063, 1.94321}, {1.65051, 2.39117}, {2.87519, 0.860111}, {1.90193, 2.01434}, {1.35583, 2.39696}, {1.88331, 1.56575}} </code></pre> <p>I am trying to generate a new set of data (output as a table) by running the function using each pair { , } in the table as the values for x and y in my function.</p> https://mathematica.stackexchange.com/q/199214 0 Bounding Solve results to named variables Карен Ла Фон Даль https://mathematica.stackexchange.com/users/65806 2019-05-27T17:48:12Z 2019-05-27T17:48:12Z <blockquote> <p>How can i bound results of my Solve function to variables properly? This metod works but causes unexpected troubles i struggle to resolve</p> </blockquote> <pre><code>q1 = {tk - T/2, w}; q2 = {tk, ak}; q3 = {tk + T/2, w}; Solve[p == 0, t]; Solve[a1*q1[]^2 + a2*q1[] + a3 == q1[] &amp;&amp; a1*q2[]^2 + a2*q2[] + a3 == q2[] &amp;&amp; a1*q3[]^2 + a2*q3[] + a3 == q3[], {a1, a2, a3}]; % /. Rule -&gt; Set; </code></pre> https://mathematica.stackexchange.com/q/195467 2 How do I create a variable that uses I? K.M https://mathematica.stackexchange.com/users/63678 2019-04-18T03:28:59Z 2019-04-18T04:09:04Z <p>I'm planning on working with a set of non-linear differential equations. A few of the equations look like:</p> <p><a href="https://i.stack.imgur.com/XQdLw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XQdLw.jpg" alt="enter image description here"></a></p> <p>Mathematica tells me that <code>I</code> is protected. Is there any way I can set <span class="math-container">$I_{H1}$</span>, for example, as a variable without having to use a different variable to represent it?</p> https://mathematica.stackexchange.com/q/194689 1 Simple question about variables into functions Wombles https://mathematica.stackexchange.com/users/52818 2019-04-05T18:56:53Z 2019-04-05T19:13:45Z <p>Im trying to write a very simple code that will solve an equation.</p> <pre><code>total = 800; side1 = x; side2 = total - 2 x; f[x_] := side1*side2 f[x] f'[x] Solve[f'[x]==0] </code></pre> <p>But what seems to be happening is that f[x] is the equation i want it to be, but it thinks the derivative is zero, which is not the case and im not sure how im messing this up. Thank you for any advice. </p> https://mathematica.stackexchange.com/q/194663 1 How to define a function, that generates matrix of variables, which can be later used in Reduce? brzepkowski https://mathematica.stackexchange.com/users/63836 2019-04-05T10:27:23Z 2019-04-05T12:28:10Z <p>My goal is to generate matrices, on which I will put different constraints in <code>Reduce</code> funcion, e.g.:</p> <pre><code>M = {{a, b}, {c, d}} Reduce[M == {{1,2},{3,4}}, {a,b,c,d}] </code></pre> <p>I want to create a function, that will generate a matrix of variables (of given size), which I could later use in such a case as the above one. So far I figured out only something like this:</p> <pre><code>TabGen[a_, n_] := Table[a &lt;&gt; ToString[i] &lt;&gt; ToString[j], {i, 1, n}, {j, 1, n}] </code></pre> <p>but when I used it in a similar case, as the first one:</p> <pre><code>A = TabGen["a", 2] Reduce[A == {{1, 2}, {3, 4}}, {a11, a12, a21, a22}] </code></pre> <p>I got:</p> <pre><code>{{"a11", "a12"}, {"a21", "a22"}} False </code></pre> <p>My gues is that this function creates a matrix of strings, which cannot be considered as variables and used later in <code>Reduce</code>. How could I solve this problem?</p> https://mathematica.stackexchange.com/q/194416 0 Separating variables in a set of equations Tugrul Temel https://mathematica.stackexchange.com/users/60365 2019-04-01T23:57:21Z 2019-04-02T14:07:36Z <p>I have a very large set of equations <code>eqs</code> with variables denoted by capital letters like PVA, QA, etc. and small letters like ica[1,2], tr[2,3] etc. And I have variables denoted by Greek letters like alfa, beta etc. My goal is to create three lists of variables, one including only capital letters, the other only small letter etc. The order of the elements is not important but variables in the final lists should not be repeated. That is, PM may appear in several equations in the system but the list of variables with capital letter should include this variable only once, no repetition. Here is an example of a system of equations to use for this simple question. Thanks.</p> <pre><code>eqs={ WF WFDIST[2, 2] == (PVA QA \[Alpha][2, 2])/QF[2, 2], EG == PQ qg + PQ qg + tr[1, 3] + tr[2, 3], QINT[1, 1] == ica[1, 1] QA, QINT[1, 2] == ica[1, 2] QA, QINT[2, 1] == ica[2, 1] QA, QINT[2, 2] == ica[2, 2] QA, QX == QA \[Theta][1, 1] + QA \[Theta][2, 1], QX == QA \[Theta][1, 2] + QA \[Theta][2, 2], QQ == aq (QD^-\[Rho]q (1 - \[Delta]q) + QM^-\[Rho]q \[Delta]q)^(-(1/\[Rho]q)) }; </code></pre> https://mathematica.stackexchange.com/q/194345 1 Apply different PlotStyles to functions with functions as variable [closed] Innerw0lf https://mathematica.stackexchange.com/users/63736 2019-03-31T22:29:13Z 2019-03-31T22:59:26Z <p>I have a function <code>func[expr,var]</code> with which I want to plot the list <code>expr[var]</code> and have different styles applied to it. When doing this with <code>ListPlot</code>, it works, but somehow this just gives the plot with the first <code>PlotStyle</code> given.</p> <p>To be specific:</p> <p><code>func[expr_, var_] := Module[{f}, f[x_] := Evaluate[expr /. var -&gt; x]; Plot[f[x], {x, 0, 10}, PlotStyle -&gt; {{Red}, {Black}}]]</code></p> <p>This gives the plot of <code>Sin[x]</code> and <code>Sin[2x]</code> both in red. How do I get one the first expression in red and the second in black?</p> https://mathematica.stackexchange.com/q/193654 1 Rearranging similar terms in an equation leastaction https://mathematica.stackexchange.com/users/27188 2019-03-20T16:25:50Z 2019-03-20T17:07:23Z <p>In a piece of code I am writing, I run into an equation of the form</p> <p><code>eqn = Subscript[x, 3] + Subscript[x, 5] + Subscript[r, 0] + 2 Subscript[ζ, 3] + Subscript[ζ, 9] == 2 Subscript[x, 4] + Subscript[ζ, 6] + Subscript[ζ, 7]</code></p> <p>In more readable <span class="math-container">$\LaTeX$</span> format, this looks like</p> <p><span class="math-container">$$x_3 + x_5 + r_0 + 2 \zeta_3 + \zeta_9 = 2 x_4 + \zeta_6 + \zeta_7$$</span></p> <p>Given such an equation with <code>Subscript[x, __]</code> as the variable of interest, I would like to rewrite it with all <span class="math-container">$x_i$</span>'s on the left hand side and everything else on the right-hand side, i.e.</p> <p><span class="math-container">$$x_3 - 2 x_4 + x_5 = -r_0 - 2\zeta_3 + \zeta_6 + \zeta_7 - \zeta_9$$</span></p> <p>(I am not interested in the <code>TeXForm</code> of course. That is trivial to extract if needed.)</p> <p>Now given such an equation (<code>eqn</code>) I can extract the left and right hand sides as</p> <p><code>lhs = eqn[]; rhs = eqn[];</code></p> <p>Then the variables on each side are</p> <p><code>vLHS = Variables[lhs]; vRHS = Variables[rhs];</code></p> <p>But how does one rearrange the equations like so?</p> <p><strong>EDIT</strong>: I already have a solution that strips each side of the equation, looks for what involves <span class="math-container">$x_i$</span> and what doesn't and reconstructs the equation in this way (by manipulating it as a list). I want to know if there's a more elegant solution.</p> https://mathematica.stackexchange.com/q/193590 0 How to show the answer in terms of another variable user63534 https://mathematica.stackexchange.com/users/63534 2019-03-19T18:49:06Z 2019-03-20T18:42:27Z <p>if we have</p> <p>A = 1; B = 44 + 1</p> <p>output :: B = 45</p> <p>how we can show B like this </p> <p>output :: B = 44 + A </p> https://mathematica.stackexchange.com/q/191677 0 Changing variables to obtain derivatives of new variables [duplicate] aghostinthefigures https://mathematica.stackexchange.com/users/62876 2019-02-16T23:33:26Z 2019-02-17T04:29:10Z <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/80241/analogue-for-maples-dchange-change-of-variables-in-differential-expressions" dir="ltr">Analogue for Maple&#39;s dchange - change of variables in differential expressions</a> <span class="question-originals-answer-count"> 1 answer </span> </li> </ul> </div> <p>Let's say that I have some symbolic expression of a function <span class="math-container">$x(t)$</span>, and would like to obtain its derivative <span class="math-container">$x'(t)$</span>. </p> <p>However, I also have the following two identities, <span class="math-container">$\xi = \omega t$</span>, and <span class="math-container">$\eta = \epsilon t$</span>. </p> <p><strong>Is there any way to have Mathematica symbolically express <span class="math-container">$x'(t)$</span> in terms of partials of <span class="math-container">$\xi$</span> and <span class="math-container">$\eta$</span>?</strong></p> <p>I've already attempted the method recommended by Alex in a related question <a href="https://mathematica.stackexchange.com/questions/9351/change-variables-in-differential-expressions">here</a>, but it doesn't seem to work for this situation. Ideally, the method would preserve the structure of the equations so that one could use DSolve or other standard symbolic manipulations on them.</p> https://mathematica.stackexchange.com/q/191391 4 Why is DSolve different when the equation is built programmatically? Joe Corneli https://mathematica.stackexchange.com/users/61630 2019-02-12T15:25:11Z 2019-02-12T20:49:55Z <p>Here is a simple differential equation.</p> <pre><code>mwe=y[x]/.First@DSolve [{y'[x]==x-2*x*y[x],y==0},y[x],x] </code></pre> <p>I get the answer <span class="math-container">$\frac{1}{2}-\frac{e^{-x^2}}{2}$</span></p> <p>If I build up the same equation in a simple program, I get a different answer:</p> <pre><code>lsolve[r_,q_,a_,eta_]=y[x]/.First@DSolve[{y'[x]==r-q*y[x],y[a]==eta},y[x],x]; nwe=lsolve[x,2*x,0,0] </code></pre> <p>After simplifying, I get the answer <span class="math-container">$\frac{1}{2}-\frac{e^{-2x^2}}{2}$</span>. Where did the extra factor of <span class="math-container">$2$</span> in the exponent come from? And how can I make it go away?</p> https://mathematica.stackexchange.com/q/190856 0 Why is ww[] not a valid variable in FindMinValue and Plot [closed] ILIa https://mathematica.stackexchange.com/users/62748 2019-02-04T18:43:26Z 2019-02-04T21:38:38Z <p>Why is <code>ww[]</code> not a valid variable when given to <code>FindMinValue</code> and <code>Plot</code>, but is a variable in <code>Minimize</code>? How can I fix the problem?</p> <pre><code>In: ww = Table[w[i], {i, 1, 6}]; a1[y1_, x_] = Function[#1*Cos[#1*0.1] + #2*2][y1, x]; Minimize[a1[ww[], 3], ww[]] FindMinValue[a1[ww[], 3], {ww[], 1}] Plot[a1[ww[], 3], {ww[], 0, 1}] Out: {0.389037, {w -&gt; -8.60334}} FindMinValue::vloc: The variable ww[] cannot be localized so that it can be assigned to numerical values. &gt;&gt; FindMinValue[a1[ww[], 3], {ww[], 1}] Plot::write: Tag Part in ww[] is Protected. &gt;&gt; Plot[a1[ww[], 3], {ww[], 0, 1}] </code></pre> https://mathematica.stackexchange.com/q/188014 0 How can I access the name of a variable inside a function? [duplicate] Darwin1871 https://mathematica.stackexchange.com/users/36575 2018-12-16T22:29:01Z 2018-12-16T22:29:01Z <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/15687/get-the-name-of-a-symbol-passed-to-a-function" dir="ltr">Get the name of a symbol passed to a function</a> <span class="question-originals-answer-count"> 1 answer </span> </li> </ul> </div> <p>How can I access the name of a variable inside a function? For example I have variables mike={some stuff} jenny={other stuff} and want to write a function f giving the following: input> f[mike] output> Mike: some stuff input> f[jenny] output> Jenny: other stuff (I know how to capitalize the first letter.)</p> https://mathematica.stackexchange.com/q/187343 0 Can I bake my own PI using your Wolfram language oven and prebuilt utensils? [closed] Francis from ResponseBase https://mathematica.stackexchange.com/users/60399 2018-12-05T02:56:23Z 2018-12-06T14:51:52Z <p>How might I override the value of the Greek letter PI within various builtin language functions in the Wolfram language? Specifically and without having to reinvent the wheel or code equivalent functions from complete scratch, I wish to replace with more useful and even perhaps more accurate values the well-worn and overworked value of 3.14159... that is used in various Fourrier transforms and other, sundry functions. </p> <p>Why you might ask. Why not would then be my reply. Working with the same figures as other historic peoples knew might cast off some of the ignorance from our contemporary perspectives and fragmented understandings. Oh, and then there is the spectacular and infamous contender and rival to proper entitlement as these number-letter things go: 3.1446055.</p> <p>I might draft a workbook to illustrate the importance to musicology and music of being able to use divergent values of PI. Yet in truth, many fields of research and study, industry, and even contemporary culture use PI in innumerable calculations ever day. All stand to potentially gain from alternate PI values. </p> <p>F.</p> https://mathematica.stackexchange.com/q/186286 0 Computing an integral : Mathematica seems to say it's diverging or not defined and I think it is J.A https://mathematica.stackexchange.com/users/58104 2018-11-19T08:46:34Z 2018-11-19T09:46:27Z <p>I would like to compute :</p> <pre><code>Element[a, Integers] Element[b, Integers] Integrate[Exp[-a^2*(x (1 - x/b^2))^2], {x, 0, Infinity}] </code></pre> <p>which is obviously not diverging. But for some reason Mathematica can't solve it. So I tried to change the variable : <span class="math-container">$x \rightarrow x (1 - x/b^2)$</span>. Now :</p> <pre><code>Integrate[Exp[-a^2*x^2]*1/(1 - (2 x)/b^2), {x, 0, Infinity}] </code></pre> <p>And then I get the answer :</p> <pre><code>ConditionalExpression[1/8 b^2 E^(-(1/4) a^2 b^4) (2 \[Pi] Erfi[1/2 Sqrt[a^2] b^2] + 2 ExpIntegralEi[(a^2 b^4)/4] + 2 Log[a^2] + Log[1/(a^2 b^4)] - 4 Log[-(1/b^2)] - Log[a^2 b^4]), (Re[b^2] &lt; 0 || b^2 \[NotElement] Reals) &amp;&amp; Re[a^2] &gt; 0] </code></pre> <p>which implies that <span class="math-container">$b^2&lt;0$</span>, because of the <span class="math-container">$- 4 Log[-(1/b^2)]$</span> I assume. But I don't get it. Even if <span class="math-container">$b^2&gt;0$</span> it's converging ! Could it mean it exists but it can't be solved analytically ?</p> <p>Or what's the mistake ? And is there a way to go around that issue ?</p> https://mathematica.stackexchange.com/q/185407 0 Inequality with assumptions Adam https://mathematica.stackexchange.com/users/61173 2018-11-06T06:52:56Z 2018-11-06T07:42:54Z <p>I would like to find 2D region formed by <span class="math-container">$(a,c) \in \mathbb{R}^2$</span> such that the inequality <span class="math-container">$f(a,c,x,y) \geq 0$</span> holds for all <span class="math-container">$x,y \in [0,1]$</span>. If I solve this inequality with reduce of the form</p> <pre><code>Reduce[f[a,c,x,y] &gt;= 0 &amp;&amp; 0 &lt;= x &lt;= 1 &amp;&amp; 0 &lt;= y &lt;= 1, {a, c}, Reals] </code></pre> <p>the result uses the variables <span class="math-container">$x$</span> and <span class="math-container">$y$</span>. Can you please help me how to input that the inequality should be true for all <span class="math-container">$x,y \in [0,1]\$</span>? Thanks in advance.</p> https://mathematica.stackexchange.com/q/183525 0 Factoring out a parameter Theorist https://mathematica.stackexchange.com/users/60363 2018-10-10T09:56:08Z 2018-10-10T10:14:21Z <p>I have some function:</p> <pre><code>f[a_,b_,c_]:=Sqrt[a^2+b^2+c^2] </code></pre> <p>Is there a way that I can factor out parameter (variable) <code>b</code> like this:</p> <pre><code>f[a_,b_,c_]:=b Sqrt[(a/b)^2+1+(c/a)^2] </code></pre> <p>in Mathematica, and call these new factored variables <code>(a/b)</code> and <code>(c/b)</code> as <code>p</code> and <code>q</code> respectively?</p>