Mathematica - Evaluating a function for different pairs of variables

In summary, the conversation discusses the use of tables to evaluate a function f(x,y) for different values of x and y. The speaker created two lists for x and y using the Table function and then used another Table function to evaluate f(x,y) for each point. They also mention using the Outer function, but found it was not useful. They then ask for help on how to output only the real evaluations of f(x,y) using the DeleteCases function. The expert suggests using the values generated from the second Table function and taking the real part of the function using Re[x].
  • #1
jimmy1066
3
0
I have a function f(x,y) that I wish to evaluate for different values of x and y.

I created two lists for x and y using table:

x = Table[x,{x,1/10,1,1/10}]
y = Table[y,{y,1/100,1/10,1/100}]

This gives me 10 values for x and 10 for y.

Now I want to evaluate my function f(x,y) for each point f(x1,y1), f(x1,y2),...,f(x2,y1) etc. This should give me 100 evaluations if I have 10 values for x and y. I've tried to evaluate by just substituting in x and y, but all this gives is 10 values corresponding to f(x1,y1), f(x2,y2), f(x3,y3),...,f(x10,y10).

Obviously I could do this by hand, but that would become a problem if I were to use say 100 values for x and for y, because that's 10000 points.

My second problem is that f(x,y) can be complex for some pairs of (x,y) and for others it has only a real part. Once I have mathematica evaluating the function correctly how do I make it output only the real evaluations?

Apologies for not using Latex. Every time I try to put in f(x,y) it just gives me [Tex]f(x,y)[/Tex]
 
Physics news on Phys.org
  • #2
For your first question perhaps Outer[f,list1,list2] might be interesting, documented here

http://reference.wolfram.com/mathematica/ref/Outer.html

or in your help browser.

For your second question perhaps DeleteCases might be interesting, documented here

http://reference.wolfram.com/mathematica/ref/DeleteCases.html

or in your help browser. Perhaps this example can give you some ideas

In[1]:= DeleteCases[{3,Pi,x,1+I}, _Complex]
Out[1]= {3,Pi,x}

And there is no need to apologize, at least not to me, for not desktoppublishingeverything
 
  • #3
Thanks for the help. Unfortunately Outer was not much use to me. Instead I made another table:
Table[f(a,b),{a,x},{b,y}] (using the tables of x and y defined in my previous post) and this appears to have solved my problem.

DeleteCases worked perfectly once I had flattened the table.

Thanks again :)
 
  • #4
jimmy1066 said:
Unfortunately Outer was not much use to me. Instead I made another table:
Table[f(a,b),{a,x},{b,y}] (using the tables of x and y defined in my previous post)
That is exactly what Outer does.
 
  • #5
Just do the following:
Code:
Values=Table[Re[f[x[[i]],y[[j]]],{i,10},{j,10}];
This will generate a table of 100 values, one for each pair of x and y. The for example, if you want the value of f for a particular combination, it would just be Values[[3,7]].

Re[x] will take the real part of x.
 

1. What is Mathematica?

Mathematica is a powerful software program used for mathematical and scientific computations, data visualization, and programming. It is commonly used by scientists, engineers, and mathematicians to solve complex problems and analyze data.

2. How do I evaluate a function for different pairs of variables in Mathematica?

To evaluate a function for different pairs of variables, you can use the Table function in Mathematica. This function allows you to specify the variables and their corresponding ranges, and then evaluates the function for each pair of variables.

3. Can I plot the results of the function evaluation in Mathematica?

Yes, you can plot the results of the function evaluation using the Plot function in Mathematica. This function allows you to specify the function, variables, and their ranges, and then plots the results on a graph.

4. How can I save the results of the function evaluation in Mathematica?

To save the results of the function evaluation, you can use the Export function in Mathematica. This function allows you to specify the format in which you want to save the results, such as a text file or image, and then saves the results to your desired location.

5. Are there any other functions in Mathematica that can be used for evaluating functions?

Yes, in addition to the Table and Plot functions, there are many other functions in Mathematica that can be used for evaluating functions. Some examples include the Manipulate function for interactive visualization, the NIntegrate function for numerical integration, and the FindRoot function for finding solutions to equations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
992
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
824
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
121
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Replies
10
Views
274
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
256
  • Precalculus Mathematics Homework Help
Replies
15
Views
627
Back
Top