Curve Fitting in MATLAB: Error Diagnosis

Click For Summary
SUMMARY

The discussion focuses on diagnosing an error encountered while performing curve fitting in MATLAB using the fittype function. The user attempted to fit a model of the form asin(bx) to their data but received an error indicating that the independent variable x was not recognized. The solution involves specifying the independent variable correctly in the fittype definition by using the 'independent' parameter, as demonstrated in the provided documentation links.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of curve fitting concepts
  • Knowledge of the fittype function in MATLAB
  • Basic understanding of mathematical modeling with sine functions
NEXT STEPS
  • Review the MATLAB documentation on fittype and its parameters
  • Explore examples of curve fitting with different models in MATLAB
  • Learn about error handling in MATLAB functions
  • Investigate advanced curve fitting techniques using the Curve Fitting Toolbox
USEFUL FOR

Data analysts, MATLAB users, and researchers involved in mathematical modeling and curve fitting who seek to troubleshoot and optimize their fitting processes.

ergospherical
Science Advisor
Homework Helper
Education Advisor
Insights Author
Messages
1,100
Reaction score
1,387
I have two 1D matrices X(1,j) and Y(1,j) of equal length. To fit Y to a model asin(bx) I tried:
Matlab:
fit = fittype(@(a,b,X), a*sin(b*X));
[fitted, gof] = fit(X, Y, fit)
coefficients = coeffvalues(fitted)
this gives the message: Error using fittype>iDeduceCoefficients
The independent variable x does not appear in the equation expression.
Use x in the expression or indicate another variable as the independent variable.


What's wrong?
 
Physics news on Phys.org
  • Like
Likes   Reactions: ergospherical
sweet, thanks
 
  • Like
Likes   Reactions: Wrichik Basu

Similar threads

  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 12 ·
Replies
12
Views
7K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K