# Tag Info

12

fF[x__Integer] := FromDigits[Join @@ IntegerDigits @ {x}] fF[1, 2] (* 12 *) fF[2, 4, 65] (* 2465 *)

11

It turns out ListSurfacePlot3D does a terribly poor job of approximating the surface in the OP, otherwise one will just apply DiscretizeGraphics to the output obtained from ListSurfacePlot3D and be done with it. But since that's not applicable here, we present an approach that uses alpha shapes to approximate the shape of the given point set by tuning a ...

6

This functionality is undocumented, but evident when Spelunking: Rescale[x, {DirectedInfinity[-1], DirectedInfinity[1]}] (* (-2 + x + Sqrt[4 + x^2])/(2 x) *) Rescale[x, {-Infinity, Infinity}] is equivalent to Rescale[x, {-Infinity, Infinity}, {0, 1}]. The relevant entry in the definition when spelunking: Needs["Spelunk"] Spelunk[Rescale] This returns ...

6

I found by trial and error that Extension-> Sqrt[I] does the job. ExpToTrig[Apart[Factor[1/(1 + x^4), Extension -> Sqrt[I]]]] \frac{\frac{1}{4}+\frac{i}{4}}{\sqrt{2} \left(-x+\frac{1+i}{\sqrt{2}}\right)}+\frac{\frac{1}{4}+\frac{i}{4}}{\sqrt{2} \left(x+\frac{1+i}{\sqrt{2}}\right)}-\frac{\frac{1}{4}-\frac{i}{4}}{\sqrt{2} ...

6

Some version of the following might be useful: ClearAll[f]; Evaluate@Thread[f[{0, 1, 2}]] := {1, 2, 3}; In this case you could also use Set instead of SetDelayed (:=), because the arguments are "atomic", not patterns. Both = and := hold their first argument unevaluated by default, so that a construct like Thread as I am using it above will only work in ...

5

It is often not necessary to use If to check arguments. Rather, since the formal arguments that appear in function definitions are almost always patterns to be matched, you can take advantage of Mathematica powerful pattern matching capabilities. Here is a fairly simple example. validColor = (_RGBColor | _GrayLevel | _Hue); colorToRGB::badarg = "bad ...

4

the main issue is that you cannot (readily*) modify the actual argument to a function Try this: InsertRows[vectors_List, matrix0_List,position_Integer] := Module[{matrix}, matrix = matrix0; Do[matrix = Insert[matrix, vectors[[i]], position], {i, Length@vectors}]; matrix] usage: matrix = InsertRows[{vector1, vector2}, matrix, ...

4

Here are a couple of approaches without using a loop, but utilising Flatten and FlattenAt: FlattenAt[Insert[matrix, {vector1, vector2}, 2], 2] {{3, 4, 5}, {10, 11, 12}, {20, 21, 22}, {6, 8, 10}, {9, 12, 15}} ir[vecs_, matrix_, pos_] := Flatten[{matrix[[1 ;; pos - 1]], vecs, matrix[[pos ;; -1]]}, 1] ir[{vector1, vector2}, matrix, 2] {{3, 4, 5}, ...

4

There are a couple of things wrong in your code: first you need to define the recursions consistently... here I've put all the t-terms on the left and t-1 on the right hand side. Next, you need to specify initial conditions (there weren't any for the fx and fy and the y was only defined implicitly (as 1-x). So here is syntactically correct code: d = 2; k = ...

4

In light of the update to OP, here's an approach by way of a mathematical formula. (* f[x_Integer, y_Integer] := x*Power[10, Ceiling[Log[10, y]]] + y *) update corrected function should be as follows: f[x_Integer, y_Integer] := x*Power[10, Floor[Log[10, y]] + 1] + y Now let's make some fake data (two sets of 10^5 64 bit integers): xlist = ...

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

4

I have moved the large addendum from my answer to How to program a F::argx message? to this post as I believe it is a better fit here. Please see that link for basic information before continuing. Handling multiple messages with an auxiliary function For full control of Message generation while retaining the canonical behavior of returning an unmatched ...

4

Put this code after your merged cell and evaluate, it should print below all expressions separately. I don't know how solid it is but worth a try: Composition[ Scan[CellPrint[Cell[#, "Input"]] &, #] &, Thread, DeleteCases[#, "\[IndentingNewLine]" | "\n", {2}] &, First, NotebookRead ]@PreviousCell[]

4

This is possibly a duplicate, but the answers given in most cases seem probably more in depth than the OP is looking for, being a newcomer to Mathematica. First you should define f as a function. f[e_] := 7.523190091795795*^-18 (1.329223358440088*^17 - 3.9876700753202693*^18 e + Sqrt[-8.944600854152669*^34 + 1.4311361366644287*^37 e^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 ...

3

Yet another way: f[x_Integer, y_Integer] := x*10^IntegerLength[y] + y f[68, 54] 6854 Or to generalize: g = Fold[#1*10^IntegerLength[#2] + #2 &, {##}] &; g[89, 68, 54] 896854

3

I believe this is fast enough p[x_] = Integrate[Exp[-y^2 + 2*I*y*x], {y, 0, Infinity}] Zf[x_] := 2 I p[x] f1[x_, p1_] := I*Im[Zf[x]] + p1*I*(1 + Zf[x]); f2[x_, p1_, p2_] := p1*(f1[x] + (2 + Zf[x])/Conjugate[Zf[x]]) - I*p2*(f1[x] - (2 - Zf[x])/Conjugate[Zf[x]]); Plot[Im[f1[x, 2]], {x, -2, 2}] Plot[Im[f2[x, 1.35, 1.45]], {x, -2, 2}] ...

3

Another way to go might be: ClearAll[func] func::arrayerr="1 or 2 must be a valid 3D-array."; func::badpara="1 must be a valid real number in the interval (0,1]."; func[_,_,c_] := Message[func::badpara,c] /; c<=0||c>1 ; func[a_,b_,_] := Message[func::arrayerr,a,b] /; !MatchQ[Dimensions[b],{_,3}] && !MatchQ[Dimensions[b],{_,3}]; ...

3

Initially I had simply wanted to tidy up your question and correct your code to make it easier to understand what you are asking for. However, in so doing, I ended up essentially solving the problem, since (as I understood it) there was not much to it after all. Therefore, I take the rather unconventional approach of restating your question in a corrected ...

3

Some parentheses and RuleDelayed instead of a Rule: dot[add[a, b, c], d, e, f] /. dot[add[y__], z__] :> (dot[#, z] & /@ add[y]) (* add[dot[a, d, e, f], dot[b, d, e, f], dot[c, d, e, f]] *) The :> prevents dot[#, z] & /@ add[y] from evaluating until after y and z have been replaced by the expressions they matched. DownValues shows the ...

3

Wouldn't it be easier to use Part? a = {{2, 3}, {4, 5}}; a[[1, 2]] = -a[[1, 2]]; a {{2, -3}, {4, 5}}

3

You For syntax is just wrong. Try r = Range[10] For[i = 1, i <= 9, i++, k = Complement[r, {i, i + 1}]; Print[k]] and avoid capital letters for your symbol names. K has a build-in meaning Information[K] K is a default generic name for a summation index in a symbolic sum.

2

You can use ReplacePart data = RandomReal[{}, {2, 2}] data = ReplacePart[data, {1, 2} -> -data[[1, 2]]] You need to reassign the result back to data You can make the above into a function if needed. flip[data_, i_, j_] := ReplacePart[data, {i, j} -> -data[[i, j]]]; data = flip[data, 1, 2] In your function, you also did something wrong. ...

2

I shall use UnitBox roughly in place of your simplefunction for the sake of example. I shall leave out data but that doesn't really affect the methods that I would use. So we start with: foo[limit_Integer] := Sum[UnitBox[i/20], {i, -limit, limit}] FixedPoint is not directly written to handle this case. Attempting to do this without introducing ...

2

Others have shown you ways to do what you want in ways which are more common to Mathematica. But I think what you really ask for (though it might not necessarily the best solution for your problem) is "pass by reference" which as such does not exist in Mathematica. But there is the possibility to use Attributes for functions and using e.g. HoldFirst will ...

2

I'm pretty sure there ought to be something cleaner. While we wait for a better answer, you may use this to return the minimum and maximum number of arguments allowed for each wavelet: nArgs[fun_] := StringCases[ToString@DownValues@fun, Shortest["ArgumentCountQ"~~__~~(n1:NumberString)~~__~~ (n2:NumberString)] :> ...

2

I was trying to do that with logs and exps but then it dawned on me: f[x_, y_] := ToExpression[StringJoin[ToString[x], ToString[y]]]

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

2

The definions of warning information func::argnums = "The func called 1 arguments, 3 arguments are needed."; func::arrayerr = "1 or 2 must be a valid 3D-array."; func::badpara = "1 must be a valid real number in the interval (0,1]."; Implementations Using the Which to check the style of arguments step-by-step. func[args___] := With[{len = ...

2

You can use replacement rules. For instance, a b + c d + e f /. {a__Plus :> List @@ a, x_ z_ :> {x z}} (*{a b, c d, e f}*) a b /. {a__Plus :> List @@ a, x_ z_ :> {x z}} (*{a b}*) This takes advantage of how ReplaceAll works in terms of the order of the list of replacement rules. It applies the first, and then applies the second to expressions ...

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