Mathematica beginner question: Function nesting

Click For Summary

Discussion Overview

The discussion revolves around creating a nested function in Mathematica that combines two existing functions, f1 and f2, while maintaining their input dependencies. Participants explore the appropriate use of assignment operators in Mathematica to achieve this goal.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant expresses difficulty in defining a function f3 that sums f1 and f2 while retaining their input arguments.
  • Another participant clarifies the difference between immediate assignment (=), delayed assignment (:=), and equality (==), suggesting the use of delayed assignment for function definitions.
  • A later reply confirms that the provided solution meets the original participant's needs, expressing gratitude for the assistance received.

Areas of Agreement / Disagreement

The discussion appears to reach a resolution with one participant successfully implementing the suggested solution, indicating agreement on the approach to function definition in Mathematica.

Contextual Notes

The initial confusion regarding assignment operators highlights the importance of understanding their distinct roles in Mathematica, which may not be clear to beginners.

Who May Find This Useful

Beginners in Mathematica, particularly those interested in function definitions and programming concepts within the software.

physicsan
Messages
2
Reaction score
0
Hello,
I'm quite new to Mathematica and stuck at a point, where I have searched for hours to find a solution, but there seems no way out.

Let's say we have two functions,
f1[x_,y_]=x+y
f2[x_,y_]=x*y

How can a build a function f3, which is e.g. the sum of the other functions f1 and f2, i.e. f3[x_, y_]=x+y+x*y, but without copy&paste, but with direct dependency on f1 and f2?

With f3=f1[x,y]+f2[x,y], the functional dependency on x and y is missing. I need a f3, which also has the same input arguments as f1 and f2 (namely x and y).
With f3[x_,y_]==f1[x,y]+f2[x,y] the functional dependency on the parameters is also not working.

Thanks you for your help,
I'm really desperate :(
 
Physics news on Phys.org
I think that you don't understand the difference between =(immediate assignment), :=(delayed assignment) and == (test for equality). You want to use := in function assignments so that the assignment is not made until you request evaluation. Try the attached notebook - I think it does what you want.
 

Attachments

Hi,

a thousand thanks! This is exactly what I was looking for! Sorry for my dummy question, it really seems so dummy now :s
Thank you again for your profound and amazingly fast help, you really made my day! :)
 
You're welcome. Glad I could help.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K