Data Regression with MATLAB

Main.MatlabDataRegression History

Hide minor edits - Show changes to output

August 13, 2020, at 01:03 PM by 136.36.211.159 -
Added line 84:
There is additional information on regression in the [[https://apmonitor.github.io/data_science|Data Science online course]].
June 21, 2020, at 04:11 AM by 136.36.211.159 -
Deleted lines 83-100:
----

(:html:)
 <div id="disqus_thread"></div>
    <script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)
March 20, 2018, at 12:51 PM by 10.37.35.33 -
Deleted lines 26-29:
(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/fi_G5P1-Ndk" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
(:htmlend:)

Changed lines 76-78 from:
%width=500px%Attach:regression_fmincon.png
to:
(:html:)
<iframe width="560" height="315" src="https://www
.youtube.com/embed/fi_G5P1-Ndk" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
(:htmlend:)
March 20, 2018, at 12:50 PM by 10.37.35.33 -
Added lines 31-32:
(:toggle hide fmincon_minimize button show="MATLAB fmincon Solution":)
(:div id=fmincon_minimize:)
Added line 78:
(:divend:)
March 20, 2018, at 12:49 PM by 10.37.35.33 -
Deleted lines 24-25:
Both regression tutorials can also be completed with [[Main/ExcelDataRegression|Excel]] and [[Main/PythonDataRegression|Python]]. Click on the appropriate link for additional information.
Added lines 78-81:

!!!! Excel and Python Solutions

The regression tutorials can also be completed with [[Main/ExcelDataRegression|Excel]] and [[Main/PythonDataRegression|Python]]. Click on the appropriate link for additional information.
March 20, 2018, at 12:48 PM by 10.37.35.33 -
Changed line 79 from:
%width=400px%Attach:regression_fmincon.png
to:
%width=500px%Attach:regression_fmincon.png
March 20, 2018, at 12:47 PM by 10.37.35.33 -
Deleted lines 32-33:
%width=400px%Attach:regression_fmincon.png
Added lines 78-79:

%width=400px%Attach:regression_fmincon.png
March 20, 2018, at 12:46 PM by 10.37.35.33 -
Added lines 28-31:

(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/fi_G5P1-Ndk" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
(:htmlend:)
March 20, 2018, at 12:40 PM by 10.37.35.33 -
Changed lines 7-8 from:
A frequent activity for scientists and engineers is to develop correlations from data. By importing the data into MATLAB, data analysis such as statistics, trending, or calculations can be made to synthesize the information into relevant and actionable information. This tutorial demonstrates how to create a linear or polynomial functions that best approximate the data trend, plot the results, and perform a basic statistical analysis. A script file of the MATLAB source code with sample data is below.
to:
A frequent activity for scientists and engineers is to develop correlations from data. By importing the data into MATLAB, data analysis such as statistics, trending, or calculations can be made to synthesize the information into relevant and actionable information. This tutorial demonstrates how to create a linear, polynomial, or nonlinear function that best approximates the data trend and how to analyze the solution. Script files of the MATLAB source code with sample data are below.
Changed lines 17-18 from:
!!!!Nonlinear Regression
to:
!!!!Nonlinear Regression with APM MATLAB
Added lines 26-75:

!!!!Nonlinear Regression with MATLAB fmincon

%width=400px%Attach:regression_fmincon.png

(:source lang=matlab:)
% clear session, close plots, clear screen
clear all; close all; clc
% data for regression
xm = [18.3447,79.86538,85.09788,10.5211,44.4556, ...
              69.567,8.960,86.197,66.857,16.875, ...
              52.2697,93.917,24.35,5.118,25.126, ...
              34.037,61.4445,42.704,39.531,29.988];
ym = [5.072,7.1588,7.263,4.255,6.282, ...
              6.9118,4.044,7.2595,6.898,4.8744, ...
              6.5179,7.3434,5.4316,3.38,5.464, ...
              5.90,6.80,6.193,6.070,5.737];
% initial parameter guess
p0 = [1,0.5,1];         
% define prediction function
yp = @(p) p(1) + p(2)./xm + p(3).*log(xm);         
% define objective function (scaled sum of squared errors)
objective = @(p) sum(((yp(p)-ym)./ym).^2);
disp(['Initial Objective: ' num2str(objective(p0))])
         
% optimize with fmincon
%[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN]
% = fmincon(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,OPTIONS)
A = [];
b = [];
Aeq = [];
beq = [];
% bounds
lb = []; % ones(3)*0.2;
ub = []; % ones(3)*1.5;
popt = fmincon(objective,p0,A,b,Aeq,beq,lb,ub);

% print results
disp(['Final Objective: ' num2str(objective(popt))])
disp(['Optimal parameters: ' num2str(popt)])

% plot results
plot(xm,ym,'ro')
hold on
plot(xm,yp(p0),'bx')
plot(xm,yp(popt),'gs')
legend('measured','initial predicted','optimal predicted')
ylabel('y')
xlabel('x')
(:sourceend:)
August 22, 2015, at 10:34 PM by 174.148.220.158 -
Changed line 22 from:
<iframe width="560" height="315" src="https://www.youtube.com/embed/DOCzyB8zj-8" frameborder="0" allowfullscreen></iframe>
to:
<iframe width="560" height="315" src="https://www.youtube.com/embed/HUkKnUWTNxc" frameborder="0" allowfullscreen></iframe>
August 22, 2015, at 09:45 PM by 174.148.220.158 -
Changed line 22 from:
<iframe width="560" height="315" src="https://www.youtube.com/embed/CejquWoc210" frameborder="0" allowfullscreen></iframe>
to:
<iframe width="560" height="315" src="https://www.youtube.com/embed/DOCzyB8zj-8" frameborder="0" allowfullscreen></iframe>
August 22, 2015, at 03:46 AM by 174.148.85.243 -
Added lines 18-19:

* [[Attach:MATLAB_nonlinear_regression.zip|MATLAB Nonlinear Regression Example Source Code]]
August 22, 2015, at 03:44 AM by 174.148.85.243 -
Added lines 9-10:
!!!!Linear and Polynomial Regression
Changed lines 17-23 from:
This regression tutorial can also be completed with [[Main/ExcelDataRegression|Excel]] and [[Main/PythonDataRegression|Python]]. Click on the appropriate link for additional information.
to:
!!!!Nonlinear Regression

(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/CejquWoc210" frameborder="0" allowfullscreen></iframe>
(:htmlend:)

Both regression tutorials
can also be completed with [[Main/ExcelDataRegression|Excel]] and [[Main/PythonDataRegression|Python]]. Click on the appropriate link for additional information.
August 21, 2015, at 01:53 AM by 10.10.146.39 -
Changed line 12 from:
<iframe width="560" height="315" src="https://www.youtube.com/embed/ro5ftxuD6is" frameborder="0" allowfullscreen></iframe>
to:
<iframe width="560" height="315" src="https://www.youtube.com/embed/CejquWoc210" frameborder="0" allowfullscreen></iframe>
August 21, 2015, at 01:30 AM by 10.10.146.39 -
Changed line 5 from:
!!!!Python Data Regression
to:
!!!!MATLAB Data Regression
August 21, 2015, at 01:17 AM by 10.10.146.39 -
Added lines 1-34:
(:title Data Regression with MATLAB:)
(:keywords data regression, MATLAB, nonlinear, polynomial, linear regression, university course:)
(:description Data Regression with MATLAB - Problem-Solving Techniques for Chemical Engineers at Brigham Young University:)

!!!!Python Data Regression

A frequent activity for scientists and engineers is to develop correlations from data. By importing the data into MATLAB, data analysis such as statistics, trending, or calculations can be made to synthesize the information into relevant and actionable information. This tutorial demonstrates how to create a linear or polynomial functions that best approximate the data trend, plot the results, and perform a basic statistical analysis. A script file of the MATLAB source code with sample data is below.

* [[Attach:MATLAB_data_regression.zip|MATLAB Data Regression Example Source Code]]

(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/ro5ftxuD6is" frameborder="0" allowfullscreen></iframe>
(:htmlend:)

This regression tutorial can also be completed with [[Main/ExcelDataRegression|Excel]] and [[Main/PythonDataRegression|Python]]. Click on the appropriate link for additional information.

----

(:html:)
 <div id="disqus_thread"></div>
    <script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)