For this assignment you are to write a simple computer program to calculate X co
ID: 3688805 • Letter: F
Question
For this assignment you are to write a simple computer program to calculate X cos(X) Y sin(Y) for a range of X and Y values, and to display the results in a table. Your program should also do some simple analysis on the results. Your program should first print out your name and ACCC nctID (e.g. jbcll), and explain to the user what the program does. For the X input, your program should read in the minimum value of X, the maximum value of X, and the change in X between data points. For the Y input, your program should read in the minimum value of Y, the maximum value of Y, and the number of data points desired in the Y direction. Once you have read in the necessary input and allocated arrays, fill the x and y vectors using the colon operator and linspace() respectively. Then calculate X cos(X) and Y sin(Y) using elementwise multiplication and a final result using matrix multiplication, as discussed above. Once both vectors and the array are filled, print out the results in a form resembling that shown in the sample above. (Don't sweat getting the numbers to exactly line up under one another, but do leave some space between the numbers so they don't run together.) Finally use Matlab functions to find or calculate the following, and report their values: The maximum value of f(x, y) over the defined range, The minimum value of f(x, y) over the defined range, The average value of x, y) over the defined range.Explanation / Answer
Below mentioned MATLAB code can be used to achive the output for above mentioned assignment:
x = 6;
steps = 1000; % Number of timesteps
Nx = 6;
alpha = 1e-3;
beta = 2;
Fs = 5; % 1O Hz sampling
deltaT = 1 / Fs;
kappa = alpha^2*Nx - Nx;
var_u = 25e-2 * eye(Nx/2); % Noise variance on prediction: 1cm
std_meas = 10e-2; % Standard deviation on measurement 5cm
F = eye(Nx);
for i = 1:Nx/2
F(i, Nx/2 + i) = deltaT;
end
Gup = eye(Nx/2) * deltaT^2/2;
Glo = eye(Nx/2) * deltaT;
G = [Gup; Glo];
% Assume start at (0,0,0) at 0 velocity
prevX = zeros(Nx, 1);
% Movement and measurements
estimate = zeros(Nx,steps);
pos = zeros(Nx,steps);
pos(:,1) = prevX;
for k = 2:steps
pos(:,k) = F * pos(:,k-1) + G * randn(3,1);
end
lms = least_mean_squares(pos(1:3,:), 0.05);
ukf = Unscented_Kalman_Filter(pos, 0.05, F, G);
figure(1);
plot(pos(1,:), pos(2,:));
hold on
plot(lms(1,:), lms(2,:), 'r');
plot(ukf(1,:), ukf(2,:), 'k');
legend('Gevolgd', 'LMS', 'Kalman');
title('Pad');
xlabel('x coördinaat [m]');
ylabel('y coördinaat [m]');
figure(2);
err_lms = sum((lms - pos(1:3,:)).^2) / 3;
err_ukf = sum((ukf(1:3,:) - pos(1:3,:)).^2) / 3;
cdf_plot(err_lms, 'r');
hold on;
cdf_plot(err_ukf, 'k');
legend('LMS', 'Kalman');
title('Cumulatieve Distributiefunctie');
xlabel('Gemiddelde kwadratische fout [m^2]');
ylabel('Fractie [-]');
For plotting f(X,Y)) = Xcos( X ) Y sin( Y ):
>> x=linspace(0,2*pi,40);
>> y=sin(y);
>> z=cos(x);
>> plot1(Xcos( X ) Y sin( Y ));
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.