Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB question help So, Ive done a similar type least squares method but am los

ID: 3601409 • Letter: M

Question

MATLAB question help

So, Ive done a similar type least squares method but am lost for how to code this to give me a raw average data graph vs the fitted line.

Initially, I have 10 different distances and 10 different values in time.

For example :

d= [ 1 2 3 4 5 6 7 8 9 10]

v= [ 1 2 3 4 5 6 7 8 9 10]

d1 = d';
v1 = v';
d2 = log(d1);
v2 = log(v1);
A = [ones(size(d2)),d2];
Y = v2;
X = inv(A'*A)*A'*Y;

k1 = exp(X(1)); %since X(1,1) is Ln*k1 exp() solves for k1
k2 = X(2); %X(2,1) is already solved for k2 therefore new element.

voltage_fitted=k1*d1.^(k2); % from d = (v/k1)^(1/k2) least squares

These were the formulas I input into matlab to give me the raw data vs fitted line graph for that particular example. For my particular example, I have to use:

h= [30 35 40 45 48 50 53 55 58 69] in inches

t= [.16 .20 .23 .30 .32 .36 .38 .40 .44 .52] in seconds

The gravity acceleration constant, time, and height are related through the formula.

              g*((T^2)/2)=h

From this equation compute gi for every hi and measured Ti, i = 1; 2; : : :,where i is the measurement number. Compute the gravitation acceleration constant as an average.Use the least squares method and the expression (1) to estimate the constant g. Showing the fitted lines based on the least-squares method and on the computed average. On the x-axis you should plot distance and on the y-axis you should plot the measured time.

The equation should be: T=Sqrt((2*h)/g)

can someone help me with this code??

Explanation / Answer

function [I] = corrindex(XData, YData, YDataM, par_number)
%
% Function for calculation of the correlation index
%
% Inputs:   XData: x data
%           YData: y data
%           YDataM: model data
%           par_number: number of model parameters
% Output:   I: correlation index
%
% Authors:
% Ivo Petras (ivo.petras@tuke.sk)
% Dagmar Bednarova (dagmar.bednarova@tuke.sk)
%
% Date: 21/002/2007
%
kx=length(XData);
ky=length(YData);
kym=length(YDataM);
if kx ~= ky
    disp('Incompatible X and Y data.');
    close all;
end
n=kym;
sey=(sum((YData-YDataM).^2))/(n-par_number);
sy=var(YData);
I=(1-(sey./sy))^0.5;
%