Mathematica: Function output to array

In summary, the person is asking for help with a Mathematica problem involving a function called F1. They want to graph the function and generate a list of ordered pairs using the function, but are having trouble doing so. They have tried using an array, but it has not worked for them. They provide a simplified version of their code and ask for assistance in achieving the desired output.
  • #1
noon0788
22
0
Hello everybody! I've got a Mathematica problem that I've been working on for a while but can't seem to solve. My code is pretty involved, so I'll simplify the dilemma for you.

F1 := Function[{x,m,b},
y = m*x+b;
Print[y]
]

I have a function called F1. If I call it like so...

F1[2,2,1]

I get an output of 5. What I'd like to do, is graph this function. I know how to graph y=mx+b, but I want to graph a bunch of ordered pairs generated by this function. I want to put in x values, get out y values, and plot them. I was trying to use an array to do this, but it hasn't been cooperating with me. How do I use this function, F1, to get something like this -> {{0,1},{1,3},{2,5},{3,7},{4,9},{5,11},{6,13},{7,15},{8,17},{9,19},{10,21}}? Thanks for your help!
 
Physics news on Phys.org
  • #2
F1Pair := Function[{x, m, b}, {x, m*x + b}];
Map[F1Pair[#, 2, 1] &, Range[0, 10]]
 

1. What is Mathematica and how does it handle function output to array?

Mathematica is a computational software program used for various tasks including mathematical and statistical calculations, data analysis, and visualization. It has a built-in function called "Array" that allows users to create arrays and populate them with function outputs.

2. How do I create an array using the "Array" function in Mathematica?

To create an array using the "Array" function, you need to specify the dimensions of the array and the function that will be used to populate it. For example, the command "Array[f, {3, 2}]" will create a 3x2 array with each element being the output of the function "f".

3. Can I use multiple functions to populate an array in Mathematica?

Yes, you can use multiple functions to populate an array in Mathematica by using the "Table" function within the "Array" function. For example, the command "Array[Table[f[i,j],{i,1,3},{j,1,2}]]" will create a 3x2 array with each element being the output of the function "f" with different values for "i" and "j".

4. How can I access and manipulate individual elements in an array in Mathematica?

You can access and manipulate individual elements in an array by using the "Part" function. For example, the command "Array[f, {3, 2}][[2, 1]]" will return the element in the second row and first column of the array. You can also use other functions such as "ReplacePart" and "MapAt" to manipulate specific elements in an array.

5. Can I convert an array to a list in Mathematica?

Yes, you can convert an array to a list in Mathematica by using the "Flatten" function. This will flatten the array into a single list, with each element being the output of the function used to populate the array. You can also use the "Normal" function to convert an array to a list of rules, where each rule corresponds to an element in the array.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
17
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
17
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • General Math
Replies
3
Views
828
Back
Top