Fitting a function in mathematica

In summary, the person is asking for advice on how to find the optimized constant x in a function f(x,y) with given values for f and y, in order to create a plot of f vs y. The suggested solution involves using Mathematica's Solve and Plot functions to solve for and plot the desired function.
  • #1
elionix
15
0
Say I have a function:

f(x,y)

I have values for f and y such that I can make a plot of f vs y... however, from the values of f and y, I am interested in finding what x is. The x value should be a constant that is optimized to fit the f vs y graph.

Is there a way I can do this in mathematica?

Thank you for any advice!
 
Mathematics news on Phys.org
  • #2
Okay, I'm a bit confused by your problem.

you mean, taking a specific example, for instance [itex]f(x,y)=(xy)^3[/itex]? Then, if you know for instance f(x,y)=14 and y=pi/2, that x should be [itex]\frac{14^{1/3}}{pi/2}[/itex]. Using that you can then see that [itex]f(x,y)=f(y)=(\frac{14^{1/3}}{pi/2} y)^3[/itex]. Trying the mathematica functions Solve and Plot should get you on your way.
 

FAQ: Fitting a function in mathematica

1. How do I fit a function in Mathematica?

Fitting a function in Mathematica involves using the built-in Fit function or the NonlinearModelFit function. These functions allow you to specify the data points and the type of function you want to fit to the data.

2. What is the difference between Fit and NonlinearModelFit?

Both functions are used for fitting functions to data, but NonlinearModelFit allows for more complex models and has additional options for fine-tuning the fitting process. It also provides more detailed output, such as confidence intervals for the fitted parameters.

3. How do I specify the type of function to fit to my data?

You can specify the type of function in the Fit or NonlinearModelFit function by using a list of functions or a symbolic expression. For example, you can use Fit[data, {1, x, x^2}, x] to fit a quadratic function to the data.

4. Can I fit a custom function in Mathematica?

Yes, you can use the NonlinearModelFit function to fit a custom function to your data. You will need to define the function beforehand using the Function or PureFunction syntax, and then pass it to NonlinearModelFit as the model to fit to the data.

5. How do I evaluate the quality of the fit?

Mathematica provides various measures for evaluating the quality of the fit, such as the R-squared value and the Adjusted R-squared value. These can be accessed through the output of the Fit or NonlinearModelFit functions. Additionally, you can plot the fitted function and the data points to visually assess the fit.

Similar threads

Back
Top