Permutations in Wolfram Alpha - wolfram-mathematica

So, the program has to print all possible permutations of a set A with elements {x, y, z, w, u, t}, with length of 3, which accomplish this condition: 'u' must not appear after 't'.
I know how to find all possible permutations like this:
A = {x, y, z, w, u, t};
Permutations[A, {3}]
But i can't figure it out how to print only the permutations where 'u' doesn't appear after 't'. Any help ?

Use DeleteCases.
DeleteCases[Permutations[A, {3}], {___, t, ___, u, ___}]

Related

2D Heat Equation Mathematica not solving analitically (DSolve) or numerically (NDSolve), what am I doing wrong?

my goal is to solve the following 2d heat conduction equation, along with initial and boundary conditions:
pde = D[u[x, y, t], t] == (c^2)*(D[u[x, y, t], {x, 2}] + D[u[x, y, t], {y, 2}]);
ic = {u[x,y,0] == 0};
bc = {Derivative[1, 0, 0][u][0, y, t] == k, u[x, 0, t] == 0, u[x, b, t] == 0,
u[a, y, t] == 0};
...but something always goes wrong when i input
sol = DSolve[{pde, bc, ic}, u[x, y, t], {x, y, t}]
I tried changing the conditions a bit to see if that is a problem on mathematica, and sometimes it works (example of this guy). I suspect there is something wrong with the derivative, but I tried using D[u[x,y,t],x]./x->0 == k but still it doesnt work. Is it even possible to solve this in Mathematica?

Mathematica: FindFit for NIntegrate of ParametricNDSolve

I`ve seen several answers for quite similar topics with usage of ?NumericQ explained and still can not quite understand what is wrong with my implementation and could my example be evaluated at all the way I want it.
I have solution of differential equation in form of ParametricNDSolve (I believe that exact form of equation is irrelevant):
sol = ParametricNDSolve[{n'[t] == g/(1/(y - f*y) + b*t + g*t)^2 - a*n[t] - c*n[t]^2, n[0] == y*f}, {n}, {t, 0, 10}, {a, b, c, g, f, y}]
After that I am trying to construct a function for FindFit or similar procedure, Nintegrating over function n[a,b,c,g,f,y,t] I have got above with some multiplier (I have chosen Log[z] as multiplier for simplicity)
Func[z_, a_, b_, c_, g_, f_] :=
NIntegrate[
Log[z]*(n[a, b, c, g, f, y][t] /. sol), {t, 0, 10}, {y, 0, Log[z]}]
So I have NIntegrate over my function n[params,t] derived from ParametricNDSolve with multiplier introducing new variable (z) wich also present in the limits of integration (in the same form as in multiplier for simplicity of example)
I am able to evaluate the values of my function Func at any point (z) with given values of parameters (a,b,c,g,f): Func(0,1,2,3,4,5) could be evaluated.
But for some reasons I cannot use FindFit like that:
FindFit[data, Func[z, a, b, c, g, f], {a, b, c, g, f}, z]
The error is: NIntegrate::nlim: y = Log[z] is not a valid limit of integration.
I`ve tried a lot of different combinations of ?NumericQ usage and all seems to lead nowhere. Any help would be appreciated!
Thanks in advance and sorry for pure english in the problem explanation.
Here is a way to define your function:
sol = n /.
ParametricNDSolve[{n'[t] ==
g/(1/(y - f*y) + b*t + g*t)^2 - a*n[t] - c*n[t]^2,
n[0] == y*f}, {n}, {t, 0, 10}, {a, b, c, g, f, y}]
Func[z_?NumericQ, a_?NumericQ, b_?NumericQ, c_?NumericQ, g_?NumericQ,
f_?NumericQ] :=
NIntegrate[Log[z]*sol[a, b, c, g, f, y][t],
{t, 0, 10}, {y, 0, Log[z]}]
test: Func[2, .45, .5, .13, .12, .2] -> 0.106107
I'm not optimistic you will get good results from FindFit with a function with so many parameters and which is so computationally expensive.

Solving two dimensional Heat equation PDE in mathematica

I am trying to solve the following equation in Mathematica but I do not know each time it only returns the equation itself instead of solving it. I tried both Dsolve and NDsolve and it was not helping me. Could anyone help me with the correct syntax?
There is a symmetry boundary condition there and the equation is in cylindrical r and z and depends on time t too.
heat= (1/r)*D[r*T[r, z, t], r] +
D[T[r, z, t], {z, 2}] == (1/(10^-4))*D[T[r, z, t], t]
NDSolve[{heat, T[0.05, z, 0] == 500, D[T[r, z, t], r] == 0},
T, {r, 0.01, 0.05}, {t, 0, 10}, {z, 0, 0.05}]
I did the same with Dsolve and no success.
If this question is not related to here would you guide me where and how to post it before you deactivate it? thank you

How to draw line 'y=x' using PolarPlot in mathematica?

Because PolarPlot should type r=... type of command.
But y=x will cause r to disappear.
How to draw that line with PolarPlot?
First, consider Plot[] which "generates a plot of f as a function of x from xmin to xmax" (I'm quoting the Mathematica documentation). You can't use it to plot a vertical line satisfying the equation x = x0, because the latter is not a function of x: instead of being single-valued, it has infinitely many values at x0.
Similarly, PolarPlot[] cannot be used to draw a straight line that passes through the origin, because its equation is not a function of θ: it has infinitely many values at a particular θ (equal to Pi/4 in the case requested), but none at all elsewhere. (Well, one could also allow the complementary angle 3Pi/4 as well.)
So I maintain it can't be done using the tools specified, short of the cheat
PolarPlot[0, {\[Theta], 0, 1},
Epilog -> Line[{Scaled[{1, 1}], Scaled[{0, 0}]}]]
I suggest you use a new function for things like this.
PolarParametricPlot[
{rT : {_, _} ..} | rT : {_, _},
uv : {_, _, _} ..,
opts : OptionsPattern[]
] :=
ParametricPlot[
Evaluate[# {Cos##2, Sin##2} & ### {rT}],
uv,
opts
]
Usage:
PolarParametricPlot[{t, 45 Degree}, {t, -10, 10}]
Here is the general polar form for a line of the form y = m x + b:
In[155]:= r /.
Solve[Eliminate[{x == r Cos[t], y == r Sin[t], y == m x + b}, {x,
y}], r]
Out[155]= {-(b/(m Cos[t] - Sin[t]))}
The solution vanishes when the y-intercept b is zero. This makes sense, since such lines are drawn at a constant angle, which is problematic since PolarPlot works by varying the angle.
You could approximate such a line by using a very small value for b, but there are probably better approaches.
You could draw the line using ListPolatPlot:
ListPolarPlot[{{Pi/4, 5}, {5 Pi/4, 5}}, Joined -> True]

Getting Indices from Mathematica's Select

How can I get the indices of a selection rather than the values. I.e.
list={3->4, 5->2, 1->1, 5->8, 3->2};
Select[list, #[[1]]==5&]; (* returns {5->2, 5->8} *)
I would like something like
SelectIndices[list, #[[1]]==5&]; (* returns {2, 4} *)
EDIT: I found an answer to the immediate question above (see below), but what about sorting. Say I want to sort a list but rather than returning the sorted list, I want to return the indices in the order of the sorted list?
Ok, well, I figured out a way to do this. Mathematica uses such a different vocabulary that searching the documentation still is generally unfruitful for me (I had been searching for things like, "Element index from Mathematica Select", to no avail.)
Anyway, this seems to be the way to do this:
Position[list, 5->_];
I guess its time to read up on patterns in Mathematica.
WRT to the question remaining after your edit: How about Ordering?
In[26]:= Ordering[{c, x, b, z, h}]
Out[26]= {3, 1, 5, 2, 4}
In[28]:= {c, x, b, z, h}[[Ordering[{c, x, b, z, h}]]]
Out[28]= {b, c, h, x, z}
In[27]:= Sort[{c, x, b, z, h}]
Out[27]= {b, c, h, x, z}
I think you want Ordering:
Sort[list, #[[1]] == 5 &]
Ordering[list, All, #[[1]] == 5 &]
(*
{5->2,5->8,3->2,1->1,3->4}
{2,4,5,3,1}
*)
Sorry, I had read your question to fast.
I think your second question is about how to sort the list according to the values of the rules. The simplest way that come to mind is by using a compare function. then simply use your solution to retrieve the indices:
comp[_ -> x_, a_ -> y_] := x < y;
Position[Sort[list, comp], 5 -> _]
Hope this helps!
Without sorting or otherwise altering the list, do this:
SelectIndex[list_, fn_] := Module[{x},
x = Reap[For[i = 1, i < Length[list], i++, If[fn[list[[i]]], Sow[i], Null];]];
If[x[[1]] == {}, {}, x[[2, 1]]]]
list={ {"foo",1}, {"bar",2}};
SelectIndex[list, StringMatchQ[ #[[1]], "foo*"] &]
You can use that to extract records from a database
Lookup[list_, query_, column_: 1, resultColumns_: All] := list[[SelectIndex[list, StringMatchQ[query, #[[column]]] &], resultColumns]]
Lookup(list,"foo")

Resources