Mathematica Calculate Pure Function in Map - Mathematica

AI Thread Summary
In Mathematica, a function t is defined to compute the square of the sum of derivatives of two expressions. The user attempts to apply this function using pure functions and the Map function to iterate over a range of values from 1 to 10. However, the current implementation fails because it does not correctly handle the substitution of different variables for the function and the argument in Map. The user seeks a solution that allows for distinct placeholders in the function while maintaining the desired functionality. Although a For loop could achieve the same result, the user prefers a cleaner solution suitable for use in plotting functions like ListPlot. The discussion highlights the challenge of using pure functions in Mathematica and the desire for a more elegant approach to iterate over multiple values.
Barioth
Messages
47
Reaction score
0
Hi!

Let's say in mathematica I declare this function

t[x_,y_]:= (x'+y')^2

Now I can call it with

$$L=1;$$
t[(#^2)+L &, (#^3)+L &]

if I call it this way it will remplace the # with s and evalute the derivative.

Now let's say I wana do this for for every L from 1 to 10.

so i got

Map[t[(#^2)+# &, (#^3)+# &],Range[1,10]]

and indeed this doesn't work. how can I tell mathematica that I want a # for my function t and one different # to use as my argument in my Map?

(*Note t I know that in this problem in make no sense to change the value of L since we're calculating the derivative. But I want to know for general purpose)
 
Physics news on Phys.org
I'm afraid I'm not terribly familiar with pure functions in MMA. However, I do have one question: could you do this in a For loop to get all your L values?
 
Ackbach said:
I'm afraid I'm not terribly familiar with pure functions in MMA. However, I do have one question: could you do this in a For loop to get all your L values?
A for loop would work, altough I want to use this in a Plot or a ListPlot. (I could do it with a For and save what's come out. But I would feel like its a ''Dirty'' solution.)

Thanks for passing by!
 

Similar threads

Replies
1
Views
2K
Replies
5
Views
3K
Replies
2
Views
1K
Replies
2
Views
2K
Replies
19
Views
2K
Replies
2
Views
2K
Back
Top