# Tag Info

8

The problem is that the function name f is substituted into Function (&) which is HoldAll. This means f[t] will not be evaluated until the Function is evaluated, such as in the OP's example problem[one][17]. So the trick is to evaluate the integrand before inserting it into the Function. Here is one way. one[x_] := 1 (*the argument*) problem[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.

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] ...

3

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], " = ...

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

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 ...

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] *)

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_]], ...

2

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

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] &] (* ...

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: ...

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] ...

Only top voted, non community-wiki answers of a minimum length are eligible