How to Linearize and Fit Data Points in MATLAB?

In summary, the question asks for the least-square curve for two different functions, f(x)=Ce^Ax and f(x)=1/(Ax+B), by using a change of variable to linearize the data points. The given data points are (-1, 6.62), (0, 3.94), (1, 2.17), (2, 1.35), and (3, 0.89). The MATLAB code provided is for finding the coefficients of a polynomial function, but it needs to be modified to fit the question's requirements. The coefficients for both functions are also provided, but the question asks for an explanation of how the change of variable affects the data.
  • #1
hunter55
3
0

Homework Statement


For the given set of data, find the least-square curve:
A) f(x)=Ce^Ax, by using the change of variable X=x, Y=ln(y), and C=e^B to linearize the data points.

B) f(x) = 1/(Ax+B), by using the change of variable X=x and Y = 1/y to linearize the data points.

x : [ -1 0 1 2 3]
y : [ 6.62 3.94 2.17 1.35 0.89]

I need the MATLAB code on how to do these 2 problems I am confused and which curve gives a better fit. ??


Homework Equations



This is the only code i know but idk how to do it with the question they are asking i need to pertain it to that

function C = poly(X,Y,M)
n=length(X);
B=zeros(1:M+1);
F=zeros(n,M+1);
for k=1:M+1
F(:,k)=X'.^(k-1);
end
A=F'*F;
B=F'*Y';
C=A\B;
C=flipud(C);


The Attempt at a Solution



These are the coefficients:
-0.0458x^3
0.5225x^2
-2.1567x
3.9040

I am confused with what the question is asking i know I am suppose to have a ans for part A and B
 
Physics news on Phys.org
  • #2
Think about what a change of variable is, then figure out how to apply that to the data.

Aka, when you make a substitution for y=ln(y), that just means you take your y list, and just take the ln of that. That now because the new measurement for what used to be the y-axis.

Does that make sense?
 
  • #3
but idk how to do it with the question they are asking

I would approach this problem by first understanding the goal of curve fitting and the method being used. Curve fitting is a process of finding a mathematical function that best represents a set of data points. In this case, we are using the least-square method, which minimizes the sum of the squared errors between the actual data points and the predicted values from the curve.

For part A, we are asked to find the least-square curve in the form of f(x)=Ce^Ax. To linearize the data points, we can use the change of variable X=x, Y=ln(y), and C=e^B. This transformation will convert the original equation into a linear form, which can be solved using the code provided. Once we have the coefficients, we can use them to generate the curve and compare it to the original data points to determine the fit.

Similarly, for part B, we need to use the change of variable X=x and Y=1/y to linearize the data points for the equation f(x) = 1/(Ax+B). Again, once we have the coefficients, we can use them to generate the curve and compare it to the original data points.

To determine which curve gives a better fit, we can use a metric such as the coefficient of determination (R^2) or the root mean square error (RMSE). A higher R^2 value or a lower RMSE value indicates a better fit.

As for the MATLAB code, I would suggest starting by defining the variables X and Y with the given data points. Then, use the provided code to calculate the coefficients for both parts A and B. Finally, use the coefficients to generate the curves and compare them to the original data points. You can also calculate the R^2 or RMSE values to determine the better fit.
 

1. What is curve fitting and why is it important?

Curve fitting is the process of finding a mathematical function that best fits a set of data points. It is important in many scientific fields such as physics, engineering, and statistics, as it allows us to make predictions and draw conclusions from data.

2. How does Matlab perform curve fitting?

Matlab uses various algorithms and methods to perform curve fitting. One commonly used method is the least squares method, which minimizes the sum of the squares of the differences between the data points and the fitted curve. Other methods include polynomial fitting, spline fitting, and nonlinear least squares fitting.

3. What type of data can be used for curve fitting in Matlab?

Matlab can perform curve fitting on both one-dimensional and multi-dimensional data. It can handle both equally spaced and unequally spaced data points, as well as data with measurement errors or noise.

4. Can Matlab handle complex functions for curve fitting?

Yes, Matlab can handle complex functions for curve fitting. It has built-in functions for fitting both linear and nonlinear functions, as well as the ability to define custom functions.

5. How can I evaluate the accuracy of the curve fitting results in Matlab?

Matlab provides various tools for evaluating the accuracy of the curve fitting results. One way is to plot the fitted curve against the original data points and visually assess the fit. Another way is to calculate the goodness of fit, such as the coefficient of determination (R-squared) or the root mean squared error (RMSE).

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
799
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • General Math
Replies
2
Views
713
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
Back
Top