Linked Questions

1
vote
2answers
78 views

The difference between ? and /; [duplicate]

I can do the following Cases[Range@10, x_ /; OddQ[x]] But why cannot I do x_?OddQ[x] instead of ...
24
votes
3answers
1k views

Quick way to use conditioned patterns when defining multi-argument function?

I have a simple function that is supposed to only accept numeric values (i.e. complex/real numbers and constant symbols e.g. Pi, E). $$f(a,b,c)=a+b+c$$ Edit: I should have chosen a less simple ...
1
vote
2answers
167 views

Weird behaviour of HoldPattern

I'm still thinking about how to implement Condition with anonymous patterns. And now I think I've found a way to implement it, but again, a suspected unclear ...
17
votes
5answers
3k views

Implement the Bisection algorithm elegantly and easily

Description: Rencently, I have finished my course Numerical Analysis, so I'd like to implement many algorithm that I have learned from that course.By this practice, I hope that I can improve my ...
0
votes
0answers
68 views

Condition in a replacing function [duplicate]

Because of "Thou shalt not copypaste", I'd like to change my pair of replacements F[foo_,foo_+1]:=bar;F[foo_,foo_-1]:=bar; (it's MUCH longer, so it actually ...
0
votes
1answer
77 views

How to use Strings and Functions With Conditions

Very new to Mathematica so this might be really simple. I have the function pow[x_,r_]:= x^r where r is rational due to ...
6
votes
2answers
4k views

How to restrict the domain of a function

I realize this question has been asked many times, but I am fairly new at Mathematica and the other answers are very complex, and certainly too complicated for this simple code I am trying to write. ...
569
votes
19answers
144k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
68
votes
6answers
6k views

How to avoid collision between optional arguments and options

Is it possible to create a function with optional arguments that also takes options? Here is a simple example. I have a function f with option "g". It also has ...
13
votes
4answers
950 views

Assessing argument type in set delayed function definitions

I'm wondering how to properly assess the type of arguments passed to functions defined with :=. I want my functions to be the most efficient, unambiguous and clear ...
17
votes
10answers
3k views

Match patterns on list of Strings

Consider the following: data={"AB","CD","AF"}; Now I would like to delete all String from data which starts with "A". Result:...
6
votes
2answers
233 views
4
votes
1answer
275 views

Why is there a difference when formulating patterns for Select and FirstPosition?

Select[{1, 2, 4, 7, 6, 2}, # > 2 &] Gives {4, 7, 6}. OK! So one should think that the following would work: ...
7
votes
2answers
928 views

Position function not always returning an answer even with no apparent problems

I'm having some problems with Position. Sometimes it will give an empty list instead of the actual position of the element I am looking for when that element is ...
8
votes
1answer
482 views

Why does pattern test work only with pure functions?

Why is it that pattern test works only with pure functions? Cases[Range[0, 70], _?(Divisible[#, 7] &)] Cases[Range[0, 70], x_?(Divisible[x, 7])] I ...

15 30 50 per page