You are on page 1of 6

Juei-Sheng Chiu - Module 1,

Computational Methods (EGRB 215)

Table of Contents
Clean Up .......................................................................................................................... 1
Honor Statement ................................................................................................................ 1
Problem 1 - Inspect the Unknown Signal ................................................................................ 1
Problem 2 - Differentiate and Integrate the low resolution signal ................................................. 2
Problem 3 - Interpolate low resolution signal ........................................................................... 3
Problem 4 - differentiate and integrate the interpolated signal ..................................................... 4
Problem 5 - Analyze Results ................................................................................................ 5

Clean Up
clear all
close all
clc

Honor Statement
On my honor, I have neither given nor received aid on this assignment, and I pledge that I am in compliance
with the VCU Honor System

% signed Joshua Chiu


% Date: 3/29/15

Problem 1 - Inspect the Unknown Signal


dat = load('Module1_data');
y_19 = cell2mat(dat.y(1,1));
y_601 = cell2mat(dat.y(1,2));
dydx_19 = cell2mat(dat.dydx(1,1));
dydx_601 = cell2mat(dat.dydx(1,2));
iy_19 = cell2mat(dat.iy(1,1));
iy_601 = cell2mat(dat.iy(1,2));
x_19 = cell2mat(dat.x(1,1));
x_601 = cell2mat(dat.x(1,2));

subplot(2,1,1);
plot(x_19, y_19, '-b', x_19, dydx_19, '-g', x_19, iy_19, '-r');
xlabel('x');
ylabel('y');
title('Unknown Functions (Low Res)');
legend('y', 'dy/dx', '\int (y)')
subplot(2,1,2);

1
Juei-Sheng Chiu - Module 1, Com-
putational Methods (EGRB 215)

plot(x_601, y_601, '-b', x_601, dydx_601, '-g', x_601, iy_601, '-r');


xlabel('x');
ylabel('y');
title('Unknown Functions (High Res)');
legend('y', 'dy/dx', '\int (y)')

Problem 2 - Differentiate and Integrate the low


resolution signal
Differntial

for i = 2:(size(y_19,2)-1) %using Central Difference method


dydxc_19(1,i-1) = (y_19(1,i+1)-y_19(1,i-1))/(x_19(1,i+1)-x_19(1,i-1));
end
figure(2);
subplot(2,1,1);
plot(x_19, dydx_19, '-b', x_19(1,2:18), dydxc_19, '-g');
xlabel('x');
ylabel('y');
title('Differentiation of Unknown Functions');
legend('dy/dx', 'Estimate')
% Integral
y_19_cumtrapz = cumtrapz(x_19, y_19)+ iy_19(1,1);
subplot(2, 1, 2);
plot(x_19, iy_19, '-b', x_19, y_19_cumtrapz, '-g');

2
Juei-Sheng Chiu - Module 1, Com-
putational Methods (EGRB 215)

xlabel('x');
ylabel('y');
title('Integration of Unknown Functions');
legend('\int (y)', 'Estimate')

Problem 3 - Interpolate low resolution signal


y_19near = interp1(x_19, y_19, x_601, 'nearest');
y_19lin = interp1(x_19, y_19, x_601, 'linear');
y_19spl = interp1(x_19, y_19, x_601, 'spline');
y_19cub = interp1(x_19, y_19, x_601, 'pchip');

figure(3);
subplot(2,2,1);
plot(x_601, y_601, '-b', x_601, y_19near, '-g');
xlabel('x');
ylabel('y');
title('Unknown Function Interpolation');
legend('y', 'nearest')

subplot(2,2,2);
plot(x_601, y_601, '-b', x_601, y_19lin, '-g');
xlabel('x');
ylabel('y');
title('Unknown Function Interpolation');
legend('y', 'linear')

3
Juei-Sheng Chiu - Module 1, Com-
putational Methods (EGRB 215)

subplot(2,2,3);
plot(x_601, y_601, '-b', x_601, y_19spl, '-g');
xlabel('x');
ylabel('y');
title('Unknown Function Interpolation');
legend('y', 'spline')

subplot(2,2,4);
plot(x_601, y_601, '-b', x_601, y_19cub, '-g');
xlabel('x');
ylabel('y');
title('Unknown Function Interpolation');
legend('y', 'cubic')

% I feel the 'spline' interpolation has the best results.

Problem 4 - differentiate and integrate the inter-


polated signal
dydxc_19spl(1,size(y_19spl,2)-2) = 0; % preallocation

%Differntiation
for i = 2:(size(y_19spl,2)-1) %using Central Difference method
dydxc_19spl(1,i-1) = (y_19spl(1,i+1)-y_19spl(1,i-1))/...

4
Juei-Sheng Chiu - Module 1, Com-
putational Methods (EGRB 215)

(x_601(1,i+1)-x_601(1,i-1));
end
figure(4);
subplot(2,1,1);
plot(x_601, dydx_601, '-b', x_601(1,2:600), dydxc_19spl, '-g');
xlabel('x');
ylabel('y');
title('Differentiation of Unknown Functions');
legend('dy/dx', 'Estimate');

% Integral
y_19spl_cumtrapz = cumtrapz(x_601, y_19spl)+ iy_601(1,1);
subplot(2, 1, 2);
plot(x_601, iy_601, '-b', x_601, y_19spl_cumtrapz, '-g');
xlabel('x');
ylabel('y');
title('Integration of Unknown Functions');
legend('\int (y)', 'Estimate');

Problem 5 - Analyze Results


% a. Interpolation does help improve the appearance of the original
% function, the plot of y_19spl versus x_601 approximates the plot of y_601
% versus x_601. That is, the intepolation using spline method very closely
% fits the original 601 element row vector containing y value data. This
% can be seen on the bottom left plot of figure 3.

5
Juei-Sheng Chiu - Module 1, Com-
putational Methods (EGRB 215)

% b. Interpolation does help improve the appearance of the differentiated


% and integrated functions with respect to y. The plot of dydxc_19spl
% (differntial of the interpolated y_19 row vector using the Central
% Difference method) versus x_601 approximates the plot of dydx_601 versus
% x_601 very well. That is, the integration using the same method as in #2
% gave a MUCH better approximation for the integral graph using the
% interpolated data than it did with the 19-element row vector. A similar
% result is seen for the integral using the trapezoid method. The integral
% function generated using the interpolated data fits the original 601
% element differential data very closerly. This is contrasted to the
% slightly poorer fit between the integral using trapezoid method and the
% original integral for the 19 element matrix.

Published with MATLAB® 7.12

You might also like