Answer To: E7 – Prof. Alam - Fall 2019, UC Berkeley E7 Homework Assignment 10: Least Squares and Linear...
Kshitij answered on Nov 25 2021
grey22/1.png
grey22/CellData.png
grey22/CellFit.png
grey22/compInput.asv
function [u1, u2] = compInput(m, delta, nSteps, pi, vi, pf, vf)
c=[ 1 delta; 0 1];
D =[delta^2/2*m; delta/m];
%%
x0=[pi; vi];
xf=[pf;vf];
%%
Cf=c^nSteps;
%%
tt=xf-(Cf*x0);
%%
CC=[];
for i=1:nSteps
k=c^(nSteps-i);
pp=k*D;
pp(:,i)=pp;
end
%%
u1=(tt\pp)';
u2 = (pinv(pp)*tt)';
end
grey22/compInput.m
function [u1, u2] = compInput(m, delta, nSteps, pi, vi, pf, vf)
c=[ 1 delta; 0 1];
D =[(delta^2)/(2*m); delta/m];
%%
x0=[pi; vi];
xf=[pf;vf];
%%
Cf=c^nSteps;
%%
tt=xf-(Cf*x0);
%%
CC=[];
for i=1:nSteps
k=c^(nSteps-i);
pp=k*D;
pp(:,i)=pp;
end
%%
u1=(tt\pp)';
u2 = (pinv(pp)*tt);
end
grey22/createFit.m
function [fitresult, gof] = createFit(Dist, RSS)
%CREATEFIT(DIST,RSS)
% Create a fit.
%
% Data for 'fit' fit:
% X Input : Dist
% Y Output: RSS
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 23-Nov-2019 16:20:16
%% Fit: 'fit'.
[xData, yData] = prepareCurveData( Dist, RSS );
% Set up fittype and options.
ft = fittype( 'poly2' );
opts = fitoptions( 'Method', 'LinearLeastSquares' );
opts.Robust = 'Bisquare';
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'fit' );
h = plot( fitresult, xData, yData );
legend( h, 'RSS vs. Dist', 'fit', 'Location', 'NorthEast' );
% Label axes
xlabel Dist
ylabel RSS
grid on
grey22/FindPolyfitOrder.m
%%
function [nMinE , pMinE, MinRelError, PolyStruct] = FindPolyfitOrder(x,y,nrange)
% data=[x, y];
for i=1:max(nrange)
[p, RelError] = MyPolyRegressor(x,y,i);
pfun=matlabFunction(poly2sym(p));
PolyStruct(i).order=i;
PolyStruct(i).polyfun=pfun;
PolyStruct(i).RelError=RelError;
PolyStruct(1).data=[x,y];
pstru(i).pcoeff=p;
end
%%
T = struct2table(PolyStruct);
%%
sortedT = sortrows(T, 'RelError');
nMinE=sortedT.order(1);
pMinE=pstru(nMinE).pcoeff;
MinRelError=sortedT.RelError(1);
end
grey22/getBasisCombinations.m
function rfHandle = getBasisCombinations(fBasis,p)
rfHandle = @(x)LOCAL_gbc(fBasis,p,x);
function y = LOCAL_gbc(basisCell,weights,x)
N = length(basisCell);
sum = 0;
for k = 1:N
sum = sum + weights(k)*basisCell{k}(x);
end
y = sum;
end
end
grey22/hw.p
v01.00v00.00��Ŕ�Ň�ß±���(��
���"%cšď�g]PÇ…bžiź@„yŻ.ô,Ľő[ł"Ó�”ÝÓ‹±Ç÷uD”‘�řgm]NÓÄĆ^ł¶‚ÝÂIgţó“‰�ł�¸·XÜ™U]4‡™¤�ëiý�\ď#Ľ2|�Ő0qčň8�Śç�ŠTEř�Ô�¤�„í
xŰ‘´ü#xňŞň}Ś2˛(Řlu(>[ŕÚƧôDÎ=ŕŮ%™¨ĺ¨‰ÉŹdľ^éÁŘÓ/;fb jÚ"]3Ý`]Ž2‹Ű
����aO�ík�‡ňvWŞşK ĘÖŰľ…6E�q/µE”ż�Kď¨Ę÷4%oĎĺ.+˝ (v�I@Ž�”Ôµ9ú‚Ů dz��JŤKÎĘ`(�ˇů�ĚŢ&ĺq�m Üa6>Ôô™¨i;2qzboiG2oÍ€Ł”d�U‚)+�ë�PRË-[�ˇá,v]Ł¬1H%ť© —çh?âDŰĘŞąĂű�z4��EŘę�ś=�MoQ¶�źóć»LĄĄ�s�YśÁÖŽxi´N˝BăŚÄpŕYN’Ěb~†Ŕ�â2ć>VÄ
ĂÎţFO ë^[„�ńţŮ=
M�-ú\[Ô-xI�µ!—–�ŔÔË“s7҇k¦Í^ăĺűD1}‚ĺ†V/˙Hv]�-‰)v‰ă»��Ł �!±–ź4bcµP}��,—TÂăőy�Çur4Ľâ…†¨…dwÉ÷uo2‰TtS4(pđ˛;^�óĘ&‹Ľ/‚�‘c˙ăę� �s�×F|�óéĘG‰Ýâę|�3·��”ôčŔòŽ%�ßš�-/„S¶u"Řő§Oe¬x4mÓ1>�ĹŚsL¦�$=�·í�� DsoĽ~¦+�oj‚�«ůüe¸eÜoµö!4›bWř Ďă0đšă5În\ZÄ0µŃVF�Äă¶flvű"‚�#Ç€QV(KS#? ÖP�¦[Gú–śĚV»%FVţ™�0ń`ŕ‰@�Ú�ą¤ľhU�hŞŇ“‹ń}86€‡śÍ�‹8§ćuj�E’�Ë´úNe4PW0ĐO(��ß_ý˛Z\1�©ä§ö �Ńn6C>Ź‡�}4›ßŤě��C�ű_µ4ě(61§2�~5—�!ă÷:Ţ´öÝ°sěh�×�"‰Đ©„l5ü#Ľ•Ž~|-.�içVĎŞ4ŰR�ĂČ°0ŹçYRBlŽ_ĺߌ¸ŮSw…®Čď(�k�96¨”u�™ź˘Ŕp±cΉt˝÷vθâ«×�xĆ�rßSZ Z÷ů‡=Ä�łÚ3Llµ˘$Ń-��ČŠŔ�–źť��ČxV#Óc Ŕç�5¦8�C㦔K9�
çU\Ö$˘ĐU�˝Ŕ®Ŕ��jľ9–ÜÚ®ĽR�e¨€kÍş˘xë-…ť‰PÓ�đ!ăŹAýVrEYO�ďr]EK¤“X@�‡�¸ępÄXRŇő=č‹ El¨«§Y—ę`VR�o¬JŰ�ą$�úł˝ĆËmŤ[ÇĹ”%$čB*X“˘,
ýsô´±€)�ąî�>iŁÓś`�)¸�™d^_¬ůs÷é'´9 ˙%轼–Vüe�Şş×ü���1ń¦Hť={ý{ÍjŽjĽ%ć�ś`V–•��|Zî"]«ţ}*ÂŰíßkÎ��ü„iAKâÓ�
]°aD^ßÁÉóH�
™_Ś�Ž�ŮlŔ)���“´CÂ;A(�˛řç§w~ějY‰�w†C‰�eŽ'„Ż<’w‚4·kŮx!�đ«˝ÔŔ�"�’çßřď�c”¨�vâąř4lŢ��mßőĎ2îĽËŠŻvü<˘ Ď˝ýÔß?âú\B.źqé�Â�ÜýŔNÓ•_Ó��¶Çő_�‹é�îě(±�É´«nř
̇(¨•J„ÉoŹ§çëÄé»öőWQ4ä�´É�ÇiŽ“�ď’X€y
ňíĘäĎä,°č[Äľ®ć.÷AçסpŻ‡Ó(�+©-*”Ë�«32�I¬“Ó�"
j›Č;_b�Î�†żÇ;’Ľ�,h&-Ľ�éöörÎ�ÔőSř}đKnŠ$«ç:�ö�ě¸#>Fs0˝O#źh�W'·L‹Í‰rrčekč�M>j‘y"ł�˘€ĹÝ{µ�ü÷rmQ“´ń�SŰgôô}ĐAÖQ!ŐM�ÁČćÖö-4BâžčL‘�Ę�'ĐČÍb™"�ë}.Ž��~Ĺ:KŢ=æ·ť�E™BV�V“ń�Żţ@‰©lk&Ħý‹�§QqźXYd{���ÜŽ§Ç=v/wń~ÓhB$Đ(µÍëŢÜE‡Cý��A|#].óŔ·|V>ť‚]k˛¨ŹHX#Ô(ł¸…CwľţŽ�WşkqĄ�IBM u\ë4SQ4Ż~5�s…��ńD?·ŞÖÔî秌îrĹč+g�SާDŔí]ó¤˘ă:'îšÍ�ćx�Žü+Ż�öú�‡ő�yg-�ˇŮó�.ĄÜŞăj�¬‚Ł6´+�C}�xË<ţNYŽš[ŘŔ€đ‘�[(ą‰t�“'Ü9eO˛ÝrglĆ�A'íy�Ł±BnÝś\ł©9» yKśŘÝR7¦Ť*�ř_q-Ż©°d�âô8ć#�AŃŢ�2ëgU@bť7)8Dß (b�¬ fń\�™Ż˘�zš4Ěȶ_/ĂT�…)ŞĄrL†°ú_�{AĂ<Ňp¬Ď†ąt(yžC`—OŮJ¬˝$Ű�„‡őD���đ
ÚJ@ßďňš–�Ć�Ţ–ţWw`�?Ff�.�Y/™ľĺµ×Łâç{úż›Ň���őŢŢ>Ý…úÂń�ďéFŠ��¸dľ/}=:.D*D‘…_Ż�=/‡�¤wx��IU,7ý0âTl�1�şë@‹ťfv�CwŹhőěŻĺŇD!ż×�
IILŔO"˱ś«ë ÂxĘ! ć2RD:ŃT±°Cßg�8wŹNć‘E°ôt¬śŃ�č�tąţç“Şą„A�+ʶz�[=î 5ćÉ”Bl>Ż¤ě—�oIöŞˇ‘Îţ$S}}´}÷˝‰˙ÓÔěë`•o?ż�„ M’áíšĘ�Tá�Í,ç‡>�F…['�ĹϬůE6Â|Đ-BţžĄwŔ´Nëwóđţ†Ch{Ĺů:—��Q*®��„Vá4�ťß‹�ŃZ6¨-�ięĆśšw0Ff)Ş~ÍE�Í�Ŕ�+��V<ĂdO�ŁÔ_łc–#ă×�YşŔ�§B×ŮŃ�ľlđ¤��}b1��(âąe@çoé�áÍ”ďSäGk§#ßt›¬_Vl6o<ż8iš��eĂ“|’‡OlÜ�ŰÉ´�Šze”řŕďÓ7 kG
ľ<ţłîK�ďcÔ�G\[Z�Z�q�Ë0··N÷�ęp@Ě�đ`g¤J)„Ę˝Ě
=Î2w;�y�¸`ČÉmUĹ�˘®��Öťt}jKsU��Ć~1é.ö·ôŤ[ŽŕŤLéSĹăׂ-ŻJ�ů�Ł5RWĎh@â7ä�TĎCl“BÄ8 ޢB@ĺ§ËÖÝ}ť�a*í�ň�–Ŕ�y€�§HđÂ܉űóá�ý1QÔ(�(‡«���#3Ź|É@Č `‡��ů�ě�iËŮă,ó�¶ęUÇö±ĹŕŚ×)ŮR»}XP�ę)Ľ78ü°Ö89ąîI’�G‹eą‰�ȸŤű\
�8s%�Ë:®öę_P�ŕĽg�
ŐŤîňÁqö¨BŤ6ů��o·k×·r2®hě�"`��öë•�şmS®›{
«I�‹H�e6đŘ;Î)gJ�ÂŁóCçę�ĹŁ± ú��ću1W‹Í1xú�=ě5=[„Ŕ<�vŘ3Âx欫xwM‰‹±Ąě»(ř–‹C@ž�…NÜb;5&`CŔqÁ5��q„Ň/‰Ű�|5e�!0íIIk)öĺtA�/’Ń%�VÖÚîsŃČKa=Š�)H|�©ç¨ň†�IĽFBŚH¸x%¨…1/�B�zĆ�TZžE?¦_�şlňBKé¸#2�cđŻé����8.űj-¸±��‹KjČš�a4Ú�˘�®‘ťÖ�â›i˝,‡—�AnDÄó�Ź¤±D�Év±«ĺŻ•†ä4çP5g} /t"÷ľëEŻ`Č~ Y‚#ž �ŕ+3,ňˇáµÁÔi¨��§˝WV�wLĄ˙kéŃíë��Fě o‚’W–ŹQ0QdäW÷:¦üĽI»70šćĚvQµ†t!˘ŔNěŐEÄ–:"Ĺ4ý)äqáŞĹi[Ěě{`°Ď�*.mŇ*¨ÜŠö ��$řóS��dŔÚĎĘĆjEű1Kóę˙ď>‘v¤���ť�¬ĽĄ�tq´â�‚ K�ŔíŃ9Ç•}3H9ű|ä ł»Jö
��ŹN÷›©çc‹xˇ�I.ÔÚĄ"JT%Ý˙•ě;íć´¬Vá+ÜüČ�‰ �×�ůTvu�Ç/2Ž‘�Ź����ö��ç�«�ŁŽ�!Py�ĺŐ�‚S´¤*;›Ň¶�G�r÷/Ň}�ő{Ř®ÍÍTuD�ařhŰ©Y#ńN`Äß*÷9ľâr-�0Ę�0+ÖÖÔś‚ĄÝ…�Î=Ů/÷§łŻ�ś {˝�@c{aĄÜ,Ńé;HgÚµ˛�s˝m8»ř4ęN‹_@ÂîŃjˇpř“/6VQ��ő᧷äća&®ş2Ő{uxq!Ý$Űípëç2Ţň•HHó< 8>„@Ąp:ľÍ»‚E6�Ę&CäRĹtůŔĄXcÍ–LSĐNe�x'Ţ/‚W�îÄS��
grey22/hw10data1.mat
Population:[17x1 double array]
Year:[17x1 double array]
grey22/hw10e72019-tz2fzxf2.pdf
E7 – Prof. Alam - Fall 2019, UC Berkeley
E7 Homework Assignment 10:
Least Squares and Linear Regression
The purpose of this lab is to improve your familiarity with solving least squares problems and performing
linear regressions using Matlab.
Note 1: A template will not be provided for this assignment. You still need to publish and submit your
m-file, so neatly organize it using code cells and comments as was done in the previous templates. The
autograder does not rely on the format of this file. You may run the autograder as many times as you
like to check your work as you complete the assignment.
Note 2: Remember to upload the following to the bCourses website:
→ All .m files including the functions that you are asked to create. Specifically:
Problem1.m, compInput.m, simRobot.m, MyPolyRegressor.m, FindPolyfitOrder.m,
PlotPolyregression.m, MMfit.m, and getBasisCombinations.m.
Directions to upload your solutions through bCourses can be found here.
The homework is due at 11:59am on Monday, November 25, 2019.
NO LATE HOMEWORK WILL BE ACCEPTED.
1. One of the first steps to selecting a cell phone signal booster for your home or office, vehicle, or
large building is to determine how strong the outside signal is. When most people talk about cell
phone signal strength, they talk about “bars” in reference to the signal strength bar indicator on
the phone. While bars are an easy way to talk about signal strength, it turns out that it’s not a
very accurate way to signal test. While many phones show the signal strength on a 5-bar scale,
some phones only have 4 bars while others have 8. Even among phones with the same number
of bars, there’s no standardization, so the strength of a 4 bar signal on one phone can be very
different than a 4 bar signal on another. Finally, bars are not very granular so for example, saying
3 bars of signal is not being very specific.
When experts discuss cell phone signal strength, they measure the signal in decibels. Decibels
are a logarithmic unit of measuring signal strength and are very precise making them ideal for
performing a signal test of just how strong of a signal is that you’re currently receiving.
Most phones have a setting we call Field Test Mode that can show you useful information about
your phone, including the signal strength in decibels. You can find the Field Test Mode on your
phone following the instructions here.
Sarah has conducted a simple experiment to find out about the relation between the Received
Signal Strength (RSS) on her phone versus distance into the Northbrae tunnel. The results of
her measurements appear below:
1 of 12
https://guides.instructure.com/m/4212/l/54353-how-do-i-upload-a-file-to-my-assignment-submission
https://www.ubersignal.com/field-test-mode#ios_always_on
https://en.wikipedia.org/wiki/Northbrae_Tunnel
E7 – Prof. Alam - Fall 2019, UC Berkeley
Distance into the tunnel (steps) Cell phone received signal strength (dB)
0 -92
5 -93
10 -105
15 -121
20 -107
25 -105
30 -101
(a) Store the presented data for “distance into the tunnel” and “cell phone received signal
strength” into row arrays called “Dist” and “RSS”, respectively. Now, plot the measured
RSS data versus distance. Label the x and y axes with...