MATLAB Matlab Linearization: Best Approximation Using Polyfit

AI Thread Summary
The discussion revolves around a user seeking assistance with data analysis in MATLAB, specifically for fitting a curve to experimental data that appears as a near-perfect line on a log-log plot. The user initially attempted to use the polyfit function but found that the resulting line did not match the expected outcome. A suggestion was made to polyfit the logarithmic values of the data directly rather than applying polyfit to the raw data first. This approach is recommended to achieve a better approximation in a least squares sense. The user expressed gratitude for the advice, indicating it resolved their issue. Additionally, there was a note about the thread's relevance to the Homework section of the forum.
IlyaZ
Messages
15
Reaction score
0
Hello,

this is my situation: I've got some data from an experiment stored in matlab. So I plot the graph and get a x^2 curve. I plot the loglog graph and see a near-"perfect" line. Now I want to create the best approximation to it (in a least squares sense).

I don't want to do that manually as it's a tedious process. So I tried polyfit, but when I compare the line generated by polyfit to the line from the experiments + after applying loglogging it doesn't match at all.

I take it I made something wrong, but I don't get what. :cry:
 
Physics news on Phys.org
Try polyfitting the log values of the data you obtained, instead of polyfitting the actual values and then plotting the log plot thereafter. If that doesn't work, then show the data you obtained and the Matlab code you used here. That helps in pinpointing where you go wrong.

Btw, I think this thread is more relevant in the Homework section.
 
Thanks for your reply I think it solved the problem.
 

Similar threads

Replies
10
Views
1K
Replies
4
Views
5K
Replies
2
Views
8K
Replies
4
Views
2K
Replies
4
Views
2K
Back
Top