Message Boards Message Boards

[✓] Define a null valued function?

GROUPS:

Dear Community, I would like to define a Null function such that if I put a list of numbers into it then split zeros, not just only one. I typed the following into Mathematica:

LinearFunction[t_] = t;
NullFunction1[t_] = 0*t;
NullFunction2[t_] = D[t, {t, 2}];
MatrixForm[LinearFunction[Table[i, {i, 1, 10}, {j, 1, 1}]]]
MatrixForm[NullFunction1[Table[i, {i, 1, 10}, {j, 1, 1}]]]
MatrixForm[NullFunction2[Table[i, {i, 1, 10}, {j, 1, 1}]]]

In the first case it gives me a 10x1 column vector, and the other two cases only give me one zero output. I would like to that NullFunction give me 10x1 zero column vector. How should I do this?

Any help would be appreciated!

POSTED BY: Adam Domjan
Answer
2 months ago

You need to use a Setdelayed (:=) instead of Set (=) to create your function:

NullFunction1[t_] := 0*t;

To understand why, type ?NullFunction1 to see your definition and then do the same for the new definition.

Regards

POSTED BY: Neil Singer
Answer
2 months ago

In fact, Most pattern matching functions should be defined with := to avoid this type of problem. I find that using = (Set) is the exception and not the rule...

POSTED BY: Neil Singer
Answer
2 months ago

Thank you very much.

POSTED BY: Adam Domjan
Answer
2 months ago

Group Abstract Group Abstract