Mathematica - get value of function at certain x

In summary, the speaker is seeking help with a homework problem involving fitting a function to data points and evaluating the function at a set of parameter values. They have 100 original points and want to generate 800 using a polynomial fit. They have the 800 parameter values in a separate file and are asking for assistance in evaluating the fitted function at those values. The conversation ends with the speaker stating they have found a solution on the Mathematica community forum.
  • #1
skrat
748
8
Hi,

I am not really sure this is the right topic to post my question in, but it is homework so...

To my data in txt file I fitted a function ##f(x)## where ##x\in [0,100]##. In the original file I had only 100 points, but now that I have a nice polynomial fit, I can get infinite number of points (on that function).

And that is exactly what I want to do. For example:

Code:
f[0.5]
returns me coordinates. (The argument in the code is parametrization of the fitted function from 0 to 1)

Now my question is:

From 100 original points, I need 800. And I have those 800 parameter values exactly defined in another txt file, let's call it values.txt. So the question is: How do I tell Mathematica to evaluate the fitted function at all the parametrization values in values.txt file? :/

Hopefully you understand what I need. I know it is simple, but I can't find it anywhere.
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
First - I believe this belongs in one of the homework threads - and someone should move it.

I don't have Mathematica handy, but once you read the 800 values into an array, I believe you can just f[data_array] and it will generate an array of 800 values, each of which is f applied to an element in data_array.
Try it out, I can't.
 
  • #3
This topic can be REmoved, not only moved. I found a solution on Mathematica community.

Thanks anyway!
 

Related to Mathematica - get value of function at certain x

1. How do I get the value of a function at a specific x value in Mathematica?

To get the value of a function at a specific x value in Mathematica, you can use the "Evaluate" function. For example, if your function is called f and you want to find the value at x=2, you can write Evaluate[f[2]].

2. Can I use a variable instead of a specific x value to get the value of a function in Mathematica?

Yes, you can use a variable in place of a specific x value to get the value of a function in Mathematica. You can define a variable using the "Set" function, such as x = 2, and then use Evaluate[f[x]] to get the value of the function at x=2.

3. Is there a way to plot a function and see the value at a specific x value in Mathematica?

Yes, you can use the "Plot" function to plot a function in Mathematica and then use the "Evaluate" function to get the value at a specific x value. For example, you can write Plot[f[x],{x,0,10}] to plot the function f and then use Evaluate[f[5]] to get the value at x=5.

4. Can I get the value of a function at multiple x values in Mathematica?

Yes, you can use the "Table" function in Mathematica to get the values of a function at multiple x values. For example, you can write Table[f[x],{x,1,5}] to get the values of the function f at x=1,2,3,4,5.

5. How can I save the values of a function at certain x values in Mathematica?

You can use the "Table" function in Mathematica to save the values of a function at certain x values in a list. For example, you can write values = Table[f[x],{x,0,10}] to save the values of the function f at x=0,1,2,...,10 in the list "values".

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
182
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top