Aaron Klapheck

clear, clc, home
fprintf('The date and time: %s \n \n', datestr(now))

disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%                                                                %')
disp('%                         Test 2.                                %')
disp('%                    Programer: Aaron Klapheck                   %')
disp('%                                                                %')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')

fprintf('\n')

% Number 1.
disp('%%%% Number 1. %%%%%')




% DoGood 17: x = -0.11, y = 0.45
% MightDo 45: x = -0.99, y = 1.01

% First find actule values

A = [34, 55; 55, 89];
b = [21; 34];
[true] = solveMatrix(A, b);
fprintf('\nActule Value of x is %f \nActual value of y is %f \n', true)




fprintf('\npart a. \n \n')

% Use function to calculate error for DoGood 17.
[decimal17, Percent17] = relError([-.11; 0.45], true)


% Use function to calculate error for MightDo 45.
[decimal45, Percent45] = relError([-0.99; 1.01], true)






fprintf('\npart b. \n \n')

% code that writes data to a .dat file.

A = 'Test2.dat';

fprintf('Write to a file called %s \n \n',A)

% write to the m file

indin = fopen(A, 'w');

    % Tell user if the file was opened sucessfully.
    if indin > 0
        fprintf('File %s opened/created sucessfully \n \n', A)
    else
        fprintf('Warning! File %s not opened/created \n \n', A)
    end % if fileID > 0

    fprintf(indin,'The error of DoGood 17 is: %f percent for x and %f percent for y \n', Percent17);
    fprintf(indin,'The error of MightDo 45 is: %f percent for x and %f percent for y \n', Percent45);
    fprintf(indin,'I would recomend MightDo 45 because it has the lowest pecentage error. \n');

cl = fclose(indin);

% stop writing

% Tell user if the file was closed sucessfully.

if cl == 0
    fprintf('File %s closed succesfully \n \n', A)
else
    fprintf('Warning! File %s not closed \n \n', A)
end % if cl == 0



% Number 2.
disp('%%%% Number 2. %%%%%')

fprintf('\npart a. \n \n')

% Read xls file
[Data, Text] = xlsread('MES08.xls');
Text
Data






fprintf('\npart b. \n \n')

% polynomial fit for n = 1.
t = Data(:,1);
h = Data(:,2);
t_new = [1:.1:5];

coefficients = FitToPoly(t, h)







fprintf('\npart c. \n \n')

% code that writes data to a .dat file.

A = 'Test2.dat';

fprintf('Write to a file called %s \n \n',A)

% write to the m file

indin = fopen(A, 'a');

    % Tell user if the file was opened sucessfully.
    if indin > 0
        fprintf('File %s opened/created sucessfully \n \n', A)
    else
        fprintf('Warning! File %s not opened/created \n \n', A)
    end % if fileID > 0

    fprintf(indin,'The constants evaluated for part (b) are: %f %f %f %f %f %f %f \n', coefficients);

cl = fclose(indin);

% stop writing

% Tell user if the file was closed sucessfully.

if cl == 0
    fprintf('File %s closed succesfully \n \n', A)
else
    fprintf('Warning! File %s not closed \n \n', A)
end % if cl == 0

% Show the data that was writen
fprintf('Wrote the folowing to %s: \n', A)
type(A)







fprintf('\npart e. \n \n')

% error for member A.
true = coefficients
measured = [0, 0, 0, 0, 0, -0.1064245, 0.498733]

[decimal, PercentA] = relError(measured, true)



% error for member B.
true = coefficients
measured = [0, 0, 0, 1, 0, 0, 0]

[decimal, PercentA] = relError(measured, true)



% code that writes data to a .dat file.

A = 'Test2.dat';

fprintf('Write to a file called %s \n \n',A)

% write to the m file

indin = fopen(A, 'a');

    % Tell user if the file was opened sucessfully.
    if indin > 0
        fprintf('File %s opened/created sucessfully \n \n', A)
    else
        fprintf('Warning! File %s not opened/created \n \n', A)
    end % if fileID > 0

    fprintf(indin,'The error for A is: %f %f %f %f %f %f %f \n', PercentA);
    fprintf(indin,'The error for B is: %f %f %f %f %f %f %f \n', PercentB);

cl = fclose(indin);

% stop writing

% Tell user if the file was closed sucessfully.

if cl == 0
    fprintf('File %s closed succesfully \n \n', A)
else
    fprintf('Warning! File %s not closed \n \n', A)
end % if cl == 0







fprintf('\npart f. \n \n')
Undefined function or variable 'PercentB'.