Tag Info

New answers tagged

0

If I correctly understand, you don't want refit the data according to new nonlinear model? Then I would try SolveAlways[(b1 x + b2 x)/(b3 + (b4/b5) x) == (c1 x)/(c2 + c3 x), {x}] It will give some relations between parameters. However it works only with polynomial equations. Not sure if I correctly understood the question.


0

You can simply consider Mean as Total of real values divided by the number of real values: n = {4, 4}; k = 3; mat = RandomReal[1, n]; mat // MatrixForm newMat = ReplacePart[mat, RandomSample[Tuples@Range@n, k] -> "nan"]; newMat // MatrixForm Total[newMat /. "nan" -> 0]/Total@Replace[newMat, {"nan" -> 0, _ -> 1}, {1}] (* {0.340737, ...


0

n = 4; m = RandomReal[1, {n, n}]; Dynamic@TableForm@m Do[ m = Partition[#, n] & @ ReplacePart[Flatten[m], Thread[RandomSample[Range[n^2], n - 1] -> "NAN"]]; Pause@.1; m = Composition[ Transpose, # /. col : {___, "NAN", ___} :> (col /. "NAN" :> Mean[DeleteCases[col, "NAN"]]) &, ...


1

to get: 1+2+3 you can use any of: exp /. Thread[syms -> (Defer /@ val)] exp /. Thread[syms -> (HoldForm /@ val)] Defer[Evaluate@exp] /. Thread[syms -> val] HoldForm[Evaluate@exp] /. Thread[syms -> val]


1

You need to do exp /. Thread[syms -> val] (* 6 *) the reason exp /. syms -> val does not work can be seen by doing trace: Trace[exp /. syms -> val] You can see it was looking for a+b+c/.{a,b,c}->{1,2,3} and since there is no pattern {a,b,c} then it does not work. With Thread, you basically break it to a->1,b->2,c->3 ...


5

Changing a__ and b__ to a_ and b_, respectively, j2[q_] := q /. b_ Cos[x__] + a_ Sin[x__] :> {{a}, {b}, {x}}; j2[h] gives $\left( \frac{\tau w}{\tau ^2 w^2+1}, \frac{1}{\tau ^2 w^2+1}, t w \right) $ and, the same change in OP's function j j3[q_] := q /. b_ Cos[x__] + a_ Sin[x__] :> Sqrt[a^2 + b^2] Sin[x + Pi/2 + ArcTan[b/a]]; j3[h] ...


2

Pattern matching takes place on (something close to) the FullForm of the expression rather than the display form that you see. You can visualize it using TreeForm: h // TreeForm I am not sure what you are attempting but I imagine your pattern was not written with this in mind. What parts did you expect to match a__, b__, and x__? What actually ...


0

I don't know why you believe your elem function does not work as it is just how I would approach this and it works as expected: elem[x_?MatrixQ, part__: All] := x[[part]]; elem[(a A + a B), 1, 1] /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}} 18


1

Since V10 you can play with Inactivate and Activate x = a A + a B /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}} // Inactivate; x[[1]] x[[2]] y = Activate[x, ReplaceAll] z = Activate[y] {{18, 18}, {18, 18}} z[[1, 1]] 18 Or, directly Activate[x][[2, 2]] 18


2

exp = (a A + a B) /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}}; exp[[1, 1]] The original code takes part [[1,1]] of the expression which is a, hence 2. Alternatively you could put parentheses around expression and rules and take part or Part[(a A + a B) /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}}, 1, ...


1

you can also use pattern test ? {{.5, .2, .49, 1, 1}, {.49, .5, .495, 1}} /. _?(.49 <= # <= .5 &) :> 0 (*{{0, 0.2, 0, 1, 1}, {0, 0, 0, 1}}*)


2

You can use Condition to get it working: {{.5, .2, .49, 1, 1}, {.49, .5, .495, 1}} /. x_ /; .49 <= x <= .5 -> 0 {{0, 0.2, 0, 1, 1}, {0, 0, 0, 1}}


3

Sort the elements of theData: DeleteDuplicates[Sort /@ theData] {1 <-> 2, 2 <-> 3} Use a function ue with Attribute Orderless: SetAttributes[ue, Orderless]; UndirectedEdge @@@ DeleteDuplicates[ue @@@ theData] {1 <-> 2, 2 <-> 3} or DeleteDuplicates[ue @@@ theData] /. ue -> UndirectedEdge {1 <-> 2, 2 <-> ...


0

Union[theData, SameTest -> (#1 === Reverse@#2 &)]


2

If you want to delete both true duplicates (i.e. 1<->2 is equal to 1<->2) and those that fulfill your definition of a duplicate you may try DeleteDuplicatesBy[theData, Sort] Otherwise you may try DeleteDuplicates[theData, # === Reverse@#2 &]


1

You can convert your data to a graph and use SimpleGraph to get rid of the duplicates. EdgeList@SimpleGraph@Graph@theData {1 <-> 2, 2 <-> 3}


0

In the chat I obtained the right answer with help from @Halirutan You want plantstate /. Rule @@ plantinput instead First, Replace is wrong because it tries to transform the entire expression expr as the documentation states. You want ReplaceAll which is /. Second, your replacement rule was wrong because what you tried had the following form ...


2

To complement some of the other answers here is one using Clip ClearAll[cutoffFuncCol]; cutoffFuncCol[threshold_, inputlist_, col_] := Module[{tmp = inputlist}, tmp[[All, col]] = Clip[tmp[[All, col]], {threshold, \[Infinity]}, {0, \[Infinity]}]; tmp] cutoffFuncCol[0.5, dataCol, 2] (* {{A, 0, 0.3}, {B, 0, 0.6}, {C, 0.9, 0.9}} *)


3

dataCol = {{A, 0.1, 0.3}, {B, 0.4, 0.6}, {C, 0.9, 0.9}}; Adding the Attribute HoldRest to your cutoffFuncCol: ClearAll[cutoffFuncColB]; SetAttributes[cutoffFuncColB, HoldRest]; cutoffFuncColB[threshold_, inputlist_, col_] := (inputlist[[All, col]] = inputlist[[All, col]] /. {x_ /; x > threshold -> x, x_ /; x < threshold -> 0}; ...


11

Try this: Replace[list, {x_, "can", _} :> {x, "can", "This"}, 1] OR list /. {x_, "can", _} :> {x, "can", "This"} {{"yes", "can", "This"}, {"yes", "can", "This"}, {"yes", "not", "fgh"}, {"yes", "can", "This"}, {"yes", "not", "h"}} As per your comment, use Alternatives (|): Replace[list, {x_, y : "can" | "cann", _} :> {x, y, "This"}, 1]


7

First, you really don't want to modify Times, as this will have all sorts of unforeseen side-effects. Your best route will be to use ** (NonCommutativeMultiply), for which you'll have to write rules that enforce the behaviour you want. Here's how you might go about that: genericRules = { (* Move numeric factors outside of NonCommutativeMultiply. *) ...


1

Given a simple directed or simple undirected weighted graph, WeightedAdjacencyMatrix gives a matrix with non-zero entries a_ij representing the weight of the edge v_i to v_j. The default value 0 implicitly describes the (dis)connectivity. Such connectivity information is needed to build a weighted graph from a matrix. For WeightedAdjacencyGraph, two ...



Top 50 recent answers are included