Data Regression with MATLAB
Main.MatlabDataRegression History
Hide minor edits - Show changes to output
Added line 84:
There is additional information on regression in the [[https://apmonitor.github.io/data_science|Data Science online course]].
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:)
Deleted lines 26-29:
<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:
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:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/fi_G5P1-Ndk" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
(:htmlend:)
Added lines 31-32:
(:toggle hide fmincon_minimize button show="MATLAB fmincon Solution":)
(:div id=fmincon_minimize:)
(:div id=fmincon_minimize:)
Added line 78:
(:divend:)
Deleted lines 24-25:
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.
Changed line 79 from:
%width=400px%Attach:regression_fmincon.png
to:
%width=500px%Attach:regression_fmincon.png
Deleted lines 32-33:
Added lines 78-79:
%width=400px%Attach:regression_fmincon.png
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:)
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:)
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>
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>
Added lines 18-19:
* [[Attach:MATLAB_nonlinear_regression.zip|MATLAB Nonlinear Regression Example Source Code]]
Added lines 9-10:
!!!!Linear and Polynomial Regression
Changed lines 17-23 from:
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.
(: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.
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>
Changed line 5 from:
!!!!Python Data Regression
to:
!!!!MATLAB Data Regression
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:)
(: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:)