Tag Info

New answers tagged

6

I believe the simplest change to your code is to replace the Return[$Failed] expressions with Sets that restore the default values of the options: ClearAll[func] Options[func] = {Method -> Automatic, WorkingPrecision -> MachinePrecision, Order -> 2}; func::badval = "`1` is not a valid value of option `2`"; func[arg1_, arg2_, opts : ...


14

This is not a bug, the tick specification used in the documentation is incorrect. The tick specification in these examples is {bottom, left} which is the short form of {bottom, left, top, right} which was an older tick specification that was deprecated in v7 (according to the docs). But, it was allowed to continue to work until v10. The form you are ...


6

I can confirm this bug under Win 7 Mathematica 10.1.0.0. A workaround for the moment is to specify all FrameTicks, e.g. Plot[Sin[x], {x, 0, 10}, Frame -> True, FrameTicks -> {ConstantArray[{-1/2, 1/2}, 2], {#, #} &@{{0, 0 °}, {Pi, 180 °}, {2 Pi, 360 °}, {3 Pi, 540 °}}}] Three more workarounds that narrow down the ...


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


1

Your Which version might be improved. In general built-in functions do not return $Failed, but themselves, so, to do it, you usually need to use Conditional expressions. This might be written in many more forms, for example, reworking a little your own answer: func::arrayerr = "`1` or `2` must be a valid 3D-array."; func::badpara = "`1` must be a valid ...


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


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


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


2

You have not defined any message text in Mathematica. The text you supply in the C code is the message tag, e.g libData->Message("myerror"); Then you need to define the actual message content in Mathematica: LibraryFunction::myerror = "Here's my message" The relevant documentation page is here.


3

One quite hacky way... introduce a dummy variable q which gets set to zero later (effectively like using a Limit) Sum[Sum[((k + q)^j) (x^j)/j!, {j, 0, \[Infinity]}], {k, 0, 10}] /. q -> 0 (* Result 1 + E^x + E^(2 x) + E^(3 x) + E^(4 x) + E^(5 x) + E^(6 x) + E^(7 x) + E^(8 x) + E^(9 x) + E^(10 x) *) A less hacky but, IMO more dangerous way... unprotect ...


2

Problems of this sort are posted from time to time in Mathematica SE. Multiple instances of Nintegrate are nested one inside another, and an inner integrand contains one of the outer variables of integration. And, from the point of view of the inner NInterate, the outer variable is undefined. (Chuy noted this in a comment above.) The solution is to have ...



Top 50 recent answers are included