0

for a formula eg y=a*x+b in book, we can use y=a*x+b and use y to quote the expression a*x+b for later using. but we also can define a function y[x_]:=a*x+b and use y[x] eg y[1] to quote the expression for later using. i wonder whether a choice is better in some cases and another choice is better in some cases or equal essentially? or ask this way: in which cases you will create a function(i think in most simple cases, just using a symbol to receive the right is ok)

Aerterliusi
  • 353
  • 1
  • 5
  • You can explore Scoping in Mathematica. – Syed Feb 03 '23 at 08:10
  • Also, eqn1= (y==a*x+b) is an option too. – rhermans Feb 03 '23 at 08:26
  • 1
    Without specifying the application this is a open-ended question. Please [edit] your question to make it focused and clear what you are after, and make it on-topic here. In general, I would avoid global assignments and use Scoping, as suggested by Syed, but that applies to all three cases . – rhermans Feb 03 '23 at 09:33
  • 1
    y=expr stores the expression: expr in y. On the other hand, f[x_]=expr is a function with an parameter y to be replaced by an actual value. – Daniel Huber Feb 03 '23 at 14:22
  • 1
    Ideally, all dependencies should be explicit. y[a_, b_, x_] := a*x+b (and with descriptive variable/parameter names). This makes the code clearer and easier to maintain. Abbreviated forms are principally for quick, limited use. – Bob Hanlon Feb 03 '23 at 16:49
  • Please, consider reading Common pitfalls. Your questions directly relate to "how does Mathematica work?" –  Apr 01 '23 at 19:46

0 Answers0