## How to find names of variables on Unity components?

I’m trying to make a Distance Joint in Unity 2D. I have it set up and it works properly in the game. However, when I go to set the ‘Connected Rigid Body’ field through code, I can’t figure out what the actual variable name is to get a reference to it.

This is the variable I want to access through code:

I want to be able to set that property like this:

distanceJoint2D.[nameofproperty] = other.transform.GetComponent<Rigidbody2D>();

Is there a way to figure out what the variable names associated with its components are?

## PlotLabel does not display variables in order

I can successfully plot a function, but I also want to include the variables in the PlotLabel. Yet, the order of the variables is not right. What am I doing wrong?

## Plotting relationship between two variables when their relationship is given by a polynomial (2)

I would like to plot the following function $$p$$ in the $$x$$-axis and $$V$$ in the $$y$$-axis. The function is given by:

62.77142857142857*(6.5+2*(18.57 - V))*(0.005*p*(18.57-V)+(6.5+2 *(18.57-V))*V)*(0.01*p*(18.57-V)+(6.5+2*(18.57-V))*V)*(0.01 *(0.65+ 0.01*(18.57-V))+0.002275*(18.57-V)*V)+0.01*(65+0.0017499999999999998*(18.57-V))*(18.57-V)*((6.5 +2*(18.57-V))*V*(0.005*p*(18.57-V)+(6.5 +2*(18.57-V))*V)-(6.5+2*(18.57-V))*V*(0.01*p*(18.57-V)+(6.5 +2*(18.57-V))*V)+2*(0.005*p*(18.57-V)+ (6.5 +2*(18.57-V))*V)*(0.01*p*(18.57-V)+(6.5+2*(18.57-V))*V))*(-0.05869954325800593*(18.57-V)+0.39*(6.5+2*(18.57-V))*(0.01*(0.65+0.01*(18.57-V))+0.002275*(18.57-V)*V))=0

Note:

I posted a similar question yesterday and @Bob Hanlon was kind enough to provide me with a very helpful code. I tried doing the same thing for this polynomial today, and Mathematica shows an error.

## How can I more quickly get the interchangeable variables in a function?

Let’s say I have an expression like a b + c d e. This is equal to: a b + c d e, a b + c e d, a b + d c e, a b + d e c, a b + e c d, a b + e d c, b a + c d e, b a + c e d, b a + d c e, b a + d e c, b a + e c d, and b a + e d c

As you can see, swapping a and b will always result in an expression equal to the original expression and swapping c, d, and e will always result in an expression equal to the original expression.

The following code is too slow for more complicated expressions. Is there a speedier way to get Mathematica to give me all equivalence classes of swappable variables such that f[a b + c d e] == {{a, b}, {c, d, e}} for some f?

SwapVariables[expr_, variable1_, variable2_] := expr /. variable1 -> replacedInSwapVariablesFunction /. variable2 -> variable1 /. replacedInSwapVariablesFunction -> variable2;  VariablesIn[expr_] := Integrate`getAllVariables[{expr}, {}];  SwappableVariablesIn[expr_] := (   vars = VariablesIn[expr];   originalVars = vars;   results = {};   While[Length[vars] > 0, (     var = First[vars];     vars = Rest[vars];     swappable = Map[TrueQ[ForAll[originalVars, SwapVariables[expr, var, #] == expr]] &, vars];     results = Append[results, Prepend[Pick[vars, swappable], var]];     vars = Pick[vars, swappable, False];   )];   results );  SwappableVariablesIn[a b + c d e]  (* {{a,b},{c,d,e}} *)

A function which can be used for a complicated expression to test timing:

DetNByN[n_] := Det[Table[Table[Indexed[x, {i, j}], {j, 1, n}], {i, 1, n}]];  First[Timing[SwappableVariablesIn[DetNByN[6]]]]  (* 10.7118 *)

## Can Mathematica factor multivariate polynomials with 4 or more variables? And with high degrees (>10)

The Mathematica documentation clearly states

the Wolfram Language routinely factors degree-100 polynomials in 3 variables

I’m interested in factoring systems of polynomials in as many as 10 or 20 variables. The systems I have are sparse in the sense that if there are 20 variables then likely no more than 3-6 variables will appear per equation and there will likely only be two terms per equation. I’ve used Solve to test on some small systems with success. To be clear, we don’t actually need to factor the polynomials necessarily. If we factor them, then we have what we need. What we really want are the roots to the system with respect to the symbolic coefficients. Solve worked for some small test systems. Factor would also work for a single polynomial, but we need a system of polynomials and I don’t see that Factor will take a system.

I’ve looked at papers by searching scholar.google.com and it seems our problem is a solved problem in mathematics. Algorithms seem to exist for such a problem, but I’m even unclear on this since the papers are too densely packed with math for me to easily understand.

Any help would be appreciated.

## Summation variables aren’t recognised as dummy variables

I’m trying to write this expression

in Mathematica, and calculate the following quantity

However, when I tried the following

Clear[g, n, v,T,P,B,r,i,j,k,l,t,w,Q,g,a,f] g = B*(Sum[Indexed[n, k]*Log[Indexed[n, k]*Indexed[v, k]],k])+ Sum[Indexed[n, f]*Indexed[w, f],f] + Sum[Sum[0.5*Indexed[Indexed[Q, l], j]*Indexed[n, l]*Indexed[n, j],j],l] + P; a = Indexed[v, r] * (g - Sum[D[g, Indexed[n, t]]*Indexed[n, t],t]) + D[g,Indexed[n, r]] Collect[a,B] //Simplify

I basically get

$$v_r * g$$

as a result of the computation and the reason is that it calculates the derivatives of $$g$$ wrt $$n_k$$s as exactly zero. Meaning that it doesn’t recognise the summation indices as dummy indices.

How can I correct my code such that the dummy summation variables will be a dummy and hence I’ll be able to perform the above calculation correctly?

## Plotting multiple dependent variables with DSolve (projectile motion with air resistance)

I wrote a working code that plots what I need using DSolve and parametric plot. Here’s an example of what it plots (and code is at the bottom).

However, I want to be able to plot multiple graphs on the same plot with k = 0, 0.01, 0.05… Something like this

I’m not sure where to vary the code without changing it too much so I can do this.

Original Code

(* Constants *) g = 9.8;  (* Differential Equation *) xcomp := x''[t] == -k x'[t]; ycomp := y''[t] == -k y'[t] - g; diff := {xcomp, ycomp}  (* Initial Conditions *) v0 = 600; \[Theta] = 60 Degree; k = 0.05; initcond = {x[0] == 0, x'[0] == v0 Cos[\[Theta]], y[0] == 0,    y'[0] == v0 Sin[\[Theta]]}  (* Solve *) eqn := Append[diff, initcond]; s = DSolve[eqn, {x[t], y[t]}, t] // Simplify y[t_] = y[t] /. s[[1]]  (* Time of Flight *) tof = Solve[y[t] == 0, t]; // Quiet T = t /. tof[[2]]  (* Plot *) ParametricPlot[{x[t], y[t]} /. s, {t, 0, T}, PlotRange -> All]

## How to replace a list/array of variables in the result?

All,

I want to know how to replace multiple variables in the result expression. To be specific, all those variables are inside the array I defined.

For a simple example, if I define input

mm5 = {a, b, c, d};

mm7 = {2, 3, 9, 8};

mm7a = mm7.mm5

Out: 2 a + 3 b + 9 c + 8 d

After that, if I define a new array

mm6 = {3, 4, 5, 7}

And I want to replace every unknown component in mm5 to be values in mm6, and to let final result of mm7a to be 23+34+95+87=119. How should I do that?

I was thinking is there anyway similar to

mm7a /. {mm5[[i]] -> mm6[[i]],{i,1,4}}

Of course, what I wrote is wrong. But is there any simple way to use /. to help me achieve this effect?? And after substituting, I want symbols in mm5 be reserved, for example, when I out put mm5 result, it is still {a, b, c, d}

I searched the whole web but I didn’t find a simple way to do it. Maybe I didn’t search it right. So I post my question here and hopefully to get some answer.

Thank you

## How to minimize that expression in four variables?

I mean $$\sqrt{w^2+(21-x)^2}+\sqrt{(20-w)^2+z^2}+\sqrt{x^2+(20-y)^2}+\sqrt{y^2+(21-z)^2}.$$

The command

Minimize[Sqrt[x^2 + (20 - y)^2] + Sqrt[y^2 + (21 - z)^2] +  Sqrt[z^2 + (20 - w)^2] + Sqrt[w^2 + (21 - x)^2], {x, y, z, w}]

is running without any response on my comp for hours. The numerical optimizations

NMinimize[ Sqrt[x^2 + (20 - y)^2] + Sqrt[y^2 + (21 - z)^2] +  Sqrt[z^2 + (20 - w)^2] + Sqrt[w^2 + (21 - x)^2], {x, y, z, w},  Method -> "DifferentialEvolution"]

{58., {x -> 11.579, y -> 8.97237, z -> 11.579, w -> 8.97237}

and the same with Method->"RandomSearch"

{58., {x -> 10.5551, y -> 9.94753, z -> 10.5551, w -> 9.94753}}