Tag Info

New answers tagged

2

You may try with this list of rules, in this order since your transformations are overlapping: rules = { Power[Subscript[X_,Subscript[a_,j_]], n_] :> Power[Subscript[\[Sigma],Subscript[a,j]], n]+ Power[Subscript[\[Mu],Subscript[a,j]], n], Times[rest1___, Subscript[X_,Subscript[a_,j_]], ...


4

If you want to do the Unprotect thing, take care to restrict your mod to the specific case: Unprotect[Dot]; Dot[a_List, b_List] /; Dimensions[a][[1]] == 1 && Dimensions[a] == Reverse@Dimensions[b] := Total@Thread@Times[First@a, First/@b] Protect[Dot]; x = {{1, 2, 3}}; y = {{4}, {5}, {6}}; Row[ { MatrixForm[x] MatrixForm[y], " = ...


0

As mentioned by bbgodfrey in a comment, you can use ParametricNDSolve. As a toy example, let's do the following: sols = ParametricNDSolve[{ x'[t] == -x[t] , y'[t] == -y[t] , e'[t] == -e[t] + x[t]/y[t] , x[0] == a, y[0] == b , e[0] == 0 } , {x, y, e} , {t, 0, 5} , {a, b} ] Then ContourPlot[Evaluate[e[a, b][c] /. sols /. c -> 1], {a, 0, 1}, ...


3

The most straight-forward adaptation of your code is the following: list = Array[x, 8]; Apply[And, Element[#, Reals]& /@ list (* x[1] ∈ Reals && x[2] ∈ Reals && x[3] ∈ Reals && x[4] ∈ Reals && x[5] ∈ Reals && x[6] ∈ Reals && x[7] ∈ Reals && x[8] ∈ Reals *) Also, you can do Element[Alternatives ...


2

The following will do what you ask, but I really can't think how it can be useful in any practical situation. a = 42.; b := a; (* note use of SetDelayed *) s1[a_?NumericQ] := Sin[a] s2[a_?NumericQ] := Sin[b] Now b tracks a and has value 42. at top-level. Therefore, for any numerical argument given s2, say π, Sin[42.] == s2[π] True To make s2 ...


1

If you are okay with using pure functions, you can do the following. expr = u[i + 1] r[i] r[i - 1]; replaceuWith[expr_, h_Function] := expr /. u[x_] :> h[x] Alternatively, replaceuWith[expr_, h_Function] := expr /. u -> h Then, replaceuWith[expr, g[# + 1] f[# - 1] &] (* f[i] g[2 + i] r[-1 + i] r[i] *) replaceuWith[expr, f[# + 1] &] (* ...


2

I believe you want expr = u[i + 1] r[i] r[i - 1] expr /. u[n_] :> g[n + 1] f[n - 1] (* f[i] g[2 + i] r[-1 + i] r[i] *)


1

The general principal I will illustrate is that code should express intention. (1) I'm going to suggest another approach. Each approach has its advantages, and due to the complicated way expressions can be evaluated (pattern restrictions, held arguments), each approach probably has drawbacks in certain situations. The following is straightforward: ...


0

A couple of observations: f[x_List] := x^2 f[xxx] (* f[xxx] *) xxx = {xxx1, xxx2}; f[xxx] (* {xxx1^2, xxx2^2} *) SetAttributes[f, HoldAll] f[xxx] (* f[xxx] *) That's half the problem solved, xxx is held to let us replace it. However: ReplaceAll[f[xxx], xxx -> {3, 4}] evaluates to ReplaceAll[f[xxx], {xxx1, xxx2} -> {3, 4}] and no match is ...


2

For the simple case in which you have variable names in flat list and their values in another, you can Thread Rule over those lists: Thread[{a, b, c} -> {13, 4, 7}] (* {a -> 13, b -> 4, c -> 7} *) This gives flat list of rules that can be used in Replace... functions. It also works for delayed rules: Thread[{a, b} :> {2+2, 10 - 5}] (* {a ...


1

Try this: rule = Subscript[k, x] -> I*κ Then any expression you may treat as follows: expression/.rule. For example: expression = Subscript[k, x]^2 + Subscript[k, x] expression /. rule returns: (* Subscript[k, x] + \!\(\*SubsuperscriptBox[\(k\), \(x\), \(2\)]\) *) (* I κ - κ^2 *) Have fun!


1

In answer to the comment about more general combining functions... vars = {X1, X2, X3, X4}; g[x1_, x2_, x3_, x4_] := (x1*x2 + x3)^x4; f[t] := Evaluate[g @@ (#[t] & /@ vars)]; Where g is specific form of the general 'combining function'. This could all be done in place without defining vars and g... f[t] := Evaluate[((#1*#2 + #3)^#4) & @@ (#[t] ...


4

Here are a number of one-liners that will define f ci = {X1, X2, X3, X4}; This first one is perhaps the easiest for_Mathematica_ newcomers to understand. Clear[f, t]; f[t_] := Evaluate[Sum[ci[[i]][t], {i, Length[ci]}]]; Definition[f] This one is pretty easy to understand too. Clear[f, t]; f[t_] := Evaluate[Plus @@ Through[ci[t]]]; Definition[f] ...


6

How about this? list = {a, Sin[b + c], d + c}; Replace[list, HoldPattern[Plus[x__]] :> Sequence[x], 1] (* ==> {a, Sin[b + c], {c, d}} *) Here, HoldPattern is needed to prevent the Plus from being swallowed. I use Replace because it allows me to specify the level 1 at which the replacement is to occur.


2

The correct way to import CSV files is to use the "CSV" import format, not "Table". You'll find this by searching the documentation for "CSV". Empty entries will be imported as "", which you can easily replace using ReplaceAll: result /. "" -> 0.0


0

Thanks to mfvonh for the answer - using ReplaceRepeated (//.) as shown below replaces everything. myexpr //. {(mess)->u,(some other mess)->v} To those in power: I unfortunately cannot accept the answer properly because after setting up the account the question is not listed as mine (and can't leave a comment because low rep = having no rights).


0

Your have to use RuleDelayed (:>) in such a case, so that the evaluation is not done immediately: myexpr = (mess) + (someOtherMess)/((mess)^3 + (someOtherMess)^2)^(1/3) and then: myexpr /. {mess :> x, someOtherMess :> y} Then you get what you want.



Top 50 recent answers are included