help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to fit a curve to a graph?


From: Doron Behar
Subject: How to fit a curve to a graph?
Date: Tue, 19 May 2020 01:39:43 +0300

Dear octaves,

I'm a bit new to Octave and I'm trying to use it as a free software
alternative to Matlab which is considered a requirement for my physics
lab course. I strongly hope I won't have to eventually install Matlab
just because I can't find the equivalents of certain Matlab features
which seem missing from Octave. My instructors are most probably not
aware of GNU octave and free software and all that Jazz so I need help.

I have an x_data and y_data for which I managed to fit a linear
polynomial function with:

[fit, regression_info] = polyfit(x_data, y_data, 1);

My instructors have asked me to (translated):

1) Perform a linear regression for test results.
2) Add to the graph the regression curve.

I'm mostly puzzled by the term "regression curve" which I hope I got
translated correctly. 

We were given the following code sample with which (If I got it
right) we can get the regression curve:

```
linear_regression = fitlm(x,y); 
R_squared = linear_regression.Rsquared.Ordinary; 
b_coefficient = linear_regression.Coefficients.Estimate(1); 
a_coefficient = linear_regression.Coefficients.Estimate(2); 
b_error = linear_regression.Coefficients.SE(1); 
a_error = linear_regression.Coefficients.SE(2); 
plot(x,y,'b.',x,linear_regression.Fitted,'k'); 
```

But it seems that the function `fitlm` is not available in GNU octave,
meaning I can't use it as is for my assignment.

What should I do? How can I give them the plot they desire? I don't even
have a sample of how this should look like. I also wish to eventually
finish the script in a Matlab compatible manner.

Besides the "regression curve", I think they have also asked me to
display on the graph the error bar according to the regression_info.
I've managed to learn I should use:

errorbar(x_data, y_data, err);

But I don't know how to compute `err` out of `regression_info`.

It's likely that I don't have a full understanding of the whole theory
of curve fitting but I hope I can get the desired results never the
less.

Regards.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]