(MATLAB) The function \"myline\" given to you in class implements line fitting f
ID: 2081874 • Letter: #
Question
(MATLAB)
The function "myline" given to you in class implements line fitting function to a set of data stored in x and y arrays: function [a b] = myline (x, y); n=length (x); sumx=sum (x); sumy=sum (y); sumxy=sum (x. *y); sumx2=sum (x.^2); a = (sumx*sumy-n*sumxy)/(sumx^2-n*sumx2); b = (sumx*surnxy-sumx2*sumy)/(sumx^2-n*sumx2); A nonlinear function y=f(x) needs to be transformed into a linear form (linearized) first. Consider the nonlinear function y = x/c_1 x + c_2 with two unknown parameters c_1 and c_2. This nonlinear function can be linearized as z = c_2 w + c_1. a) What is the variable change in this linearizing transformation? b) Write a script file (program) that uses "myline" function to fit y = x/c_1 x + c_2 to the following x and y data (find c_1 and c_2 using least-square error). x and y are already created and you do not need to create them.Explanation / Answer
y=x/(c1 x + c2) can be modified as
(1/y)=c2 (1/x)+c1
so z=1/y and w =1/x
so first find z and w from x and y
then call my line Function
as
[c2 c1]=myline(w,z)
Use following code to calculate c1 and c2 .
w=(1./x);
z=(1./y);
[c2 c1]=myline(w,z);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.