I am trying to find the least squares fit to the polar equation below: 2r(1+Ecos
ID: 3079900 • Letter: I
Question
I am trying to find the least squares fit to the polar equation below: 2r(1+Ecos(theta)) = L which can then be written as: 2r = E(-2rcos(theta))+L So y= 2r and x = 2r* cos(theta) ) I have already input the data into the script file: clear all; close all; clc; r=[42895,42911,42851,42779,42774,42764,42750,42744,42749,42749,42894]; theta=[-0.1289,-0.1352,-0.1088,-0.0632,-0.0587,-0.0484,-0.0280,-0.0085,0.0259,0.0264,0.1282]; [m b]=mylinfit(-2*transpose(r)*cos(theta),2*r); q=[m,b]; esval=polyval(q,-2*transpose(r)*cos(theta)); plot(-2*transpose(r)*cos(theta),2*r,'o',-2*transpose(r)*cos(theta),esval,'-') xlabel('Xk'); ylabel('Yk'); title('Least Squares Linear Fit k=1-13'); I am also using the following function to find the least squares fit function [m,b] = mylinfit(x,y) n=length(x); numerator_slope= n*sum(x.*y)-sum(x)*sum(y); denominator_glob=n*sum(x.^2)-(sum(x))^2; m=numerator_slope/denominator_glob; numerator_int= (sum(x.^2))*sum(y)-sum(x)*sum(x.*y); b=numerator_int/denominator_glob; end For some reason the least square line is way off. Can someone please check my script file and see any issues? Thanks!Explanation / Answer
i am sure you are script file right because same type model we discussed in class in last month.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.