Message Boards Message Boards

0
|
2583 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Define a null valued function?

Posted 7 years ago

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
3 Replies
Posted 7 years ago

Thank you very much.

POSTED BY: Adam Domjan

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

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract