Tag Info

New answers tagged

0

Very similar to your other question. Replace the following definitions in your code: u[t_] := 1/ b2[t]*(-(a21[t]*x1[t] + a22[t]*x3'[t]) + r2dot[t] - c (x3'[t] - rdot[t]) - k*2/Pi*ArcTan[((x3'[t] - rdot[t]) + c (x3[t] - r[t]))]); sol = First[NDSolve[ {x1'[t] == a11[t]*x1[t] + a12[t]*x3'[t] + a13[t]*x3[t] + b1[t]*u[t], x3''[t] == ...


0

Sadly the undocumented mechanism behind Simon's splitstyle no longer works in Mathematica 10.0 or 10.1. Post-processing(1),(2) remains an option as does use of ListPlot. While pure post-processing is possible, in a bid to make this answer unique I shall instead define styleSplitter as a function that extracts the PlotStyle option from an unevaluated Plot ...


2

Here's a method using replacement rules. This function takes a list of the noncommuting variables and returns the simplification rules: commuteRules[noncom_] := { NonCommutativeMultiply[x___, 1, z___] -> NonCommutativeMultiply[x, z], NonCommutativeMultiply[x___, a_ y_. /; FreeQ[a, Alternatives @@ noncom], z___] -> a NonCommutativeMultiply[x, ...


7

One way to achieve what is asked in the question, is to introduce an identity id which commutes with all quantities but can be used together with X and Y to efficiently tell NonCommutativeMultiply how to treat scalars a, b, and c: Clear[id] id /: NonCommutativeMultiply[id, y_] := y id /: NonCommutativeMultiply[x_, id] := x ...


5

There are two parts that are immediately suspicious to me: your phase calculation and finalState. Your calculation of phase is rather inefficient. Table is a good construct, but it is often slow. The form you have is not even allowing it to speed things up: you are nesting them instead of using both iterators with one call. Honestly, I would not even ...


4

You need to define how you expect this special object to interact with functions, and which functions should handle it. Based on your example I think you want the label to be stripped from the object when an operation is performed? You can generally use UpSet or TagSet (or more frequently their Delayed counterparts) to provide handling rules as needed. ...


2

Although this is not an answer to the question as put, the problem can be solved completely with Mathematica as follows. This is also a hint to try alternative formulations in mathematica if a specific one does not succeed. Assuming, of course, that the problem is in the center of interest. The easiest way to obtain the values of a[n,m] is to start with ...


1

I will not answer the failure of in-built functions but present an alternative approach: f[m_, u_] := With[{r = {{-1, 0}, {0, -1}, {-1, -1}}}, ReplacePart[m, u -> Total[(Extract[m, u + #1] &) /@ r]]]; sa[m_, n_] := Module[{s, p}, s = Normal@SparseArray[{{i_, 1} -> 1, {1, j_} -> 1}, {m, n}, "x"]; p = Position[s, "x"]; Fold[f[#1, #2] ...


3

This question is probably a duplicate of: Using pure functions in Table If not I think you want FoldList: FoldList[f, x, Table[If[m < 3, m, m + 1], {m, 5}]] {x, f[x, 1], f[f[x, 1], 2], f[f[f[x, 1], 2], 4], f[f[f[f[x, 1], 2], 4], 5], f[f[f[f[f[x, 1], 2], 4], 5], 6]} As stated I think this is a duplicate but there may be methods applicable here ...


4

One way is to use With ComposeList[ Table[ With[{m = m}, Which[m < 3, f[#, m] &, m < 6, f[#, m + 1] &]], {m, 1, 5, 1}], x] {x, f[x, 1], f[f[x, 1], 2], f[f[f[x, 1], 2], 4], f[f[f[f[x, 1], 2], 4], 5], f[f[f[f[f[x, 1], 2], 4], 5], 6]}


0

Use Evaluate res1 = ComposeList[ Table[ Evaluate[Which[ m < 3, f[#, m], m < 6, f[#, m + 1]]] &, {m, 5}], x] {x, f[x, 1], f[f[x, 1], 2], f[f[f[x, 1], 2], 4], f[f[f[f[x, 1], 2], 4], 5], f[f[f[f[f[x, 1], 2], 4], 5], 6]} res2 = ComposeList[ Table[ Evaluate[Piecewise[{ {f[#, m], m < 3}, {f[#, m + ...


1

Unfortunately, I think formal differentiation of Product only works if you specify a numerical value for the limit n: For example, tmp = With[{n = 3}, Sum[Product[MyVal[i, j]^(1/n), {j, 1, n}], {i, 1, n}]]; FullSimplify[D[tmp, MyVal[i1, j1], NonConstants -> {MyVal}]]


5

I'm totally cheating here, but you can use SemanticInterpretation in v10 to get you there. SemanticInterpretation[StringRiffle[{1, Plus, 2, Times, 3}, " "]] 7 :)


3

This solution may be simple and rather "robust": ToExpression[ StringJoin[ToString /@ list /. {"Plus" -> "+", "Times" -> "*"}] ] You may try it on: list = {1, Plus, 2, Times, 3, Plus, "PlusPlus"} where it correctly returns: PlusPlus+7


4

list //. ({x___, PatternSequence[a_, u : #, b_], y___} :> {x, u[a, b], y} & /@ {(Times | Divide), (Plus | Subtract)}) (* {7} *) f[list_] := list //. ({x___, PatternSequence[a_, u : #, b_], y___} :> {x, u[a, b], y} & /@ {(Times | Divide), (Plus | Subtract)}) {#, f@#} & /@ (Riffle[{a, b, c}, #] & /@ ...


4

I can confirm the above incorrect results are due to a bug in the Intel MKL library shipping with Mathematica 10.1 which affects FFT convolution. The problem is only known to be triggered on some processors (for example AMD chips, or virtual machine emulated CPUs). The following workaround will use an alternative implementation that does not rely on MKL ...


2

Updated version To be more in line with what the OP wanted, we have the following updated code. Given inputs (in order) g, totargs = 5, args = {x[1],x[4]}, and targets = {1,4}, if we call the function partialEvaluate[func_, totargs_ args_, targets_] := Block[{num = 1} , Evaluate[func @@ Table[ If[MemberQ[targets, i], args[[i]], Slot[num++]] , {i, ...


1

Since mathematica does not use currying evaluation like language like haskell, you should do the currying for partial evaluation by yourself. Here is some simple example: In[1]:= addx[x_] := Function[y, x + y] In[2]:= addx[3][4] Out[2]:= 7 In[3]:= add3 = addx[3] Out[3]:= Function[y$, 3 + y$] In[4]:= add3[4] Out[4]:= 7 In general, you should make the ...


0

Clear[log1p] log1p[x_, n : _Integer?Positive : 2] := (Series[Log[1 + y], {y, 0, n}] // Normal) /. y -> x log1p[1.0*^-15] 9.999999999999995*^-16


3

Problem The problem with Log[1. + 1.*^-15] not yielding 1. is not due to Log, but to MachinePrecision inputs, which I think the OP implied in the question statement: 1 + 1.*^-15 % - 1 (* 1. 1.11022*10^-15 *) So Log[1 + 1.*^-15] does return the right answer, 1.11022*10^-15, for the actual input. Solution Here is a simple way to get log1p-type ...



Top 50 recent answers are included