Академический Документы
Профессиональный Документы
Культура Документы
We see that as alpha increases, the maximum length of the ladder that is able to negotiate the corner increases too. This makes sense because as alpha approaches 180 degrees, the hallway becomes straight, and will be able to accommodate longer lengths of ladders.
2. a) Objective function
function F = lab08a(k) % This function lab08a takes in a vector k =[k1 k2 k3], where k is a 1 by 3 matrix % containing the values of k1, k2 and k3. It will calculate the model y % values using the input k. Following which, it will calculate the sum of % square deviation F as an output of this function. if ~(size(k)==[1 3]) error('Wrong input matrix dimensions') % this is to prevent any input of data that does not have the correct % dimensions end %% Loading experimental data load lab08data %% Calculating model y values for n=1:numel(x) ymodel(n)=(k(1)*exp(k(2)*x(n)))+k(3); % calculating model y values using input k's and equation(1) for all % tabulated values of x end %% Calculating sum of square deviation F F=0; for m=1:numel(x) F=F+(y(m)-ymodel(m))^2; end
xlabel('x'); ylabel('y'); title('A graph of y versus x, with optimum values of k1, k2 and k3'); legend('Model values','Experimental values');
c) Objective function
function F = lab08c(k) % This function lab08a takes in a vector k =[k1 k2 k3], where k is a 1 by 3 matrix % containing the values of k1, k2 and k3. It will calculate the model y % values using the input k. Following which, it will calculate the sum of % square deviation F as an output of this function. if ~(size(k)==[1 3]) error('Wrong input matrix dimensions') % this is to prevent any input of data that does not have the correct % dimensions end %% Loading experimental data load lab08data %% Calculating model y values for n=1:numel(x) ymodel(n)=(k(1)*x(n)^2+k(2)*x(n)+k(3));
% calculating model y values using input k's and equation(2) for all % tabulated values of x end %% Calculating sum of square deviation F F=0; for m=1:numel(x) F=F+(y(m)-ymodel(m))^2; End
d) Using polyfit(x,y,2): k1=0.0400, k2=-0.8129 and k3=11.8961 These values obtained from polyfit agree with the values from 2(C). Using the polyval function: polyval([0.0400 -0.8129 11.8961], 4.3) = 9.1392