# Stony Brook University MATLab

Hi, I need help on a programming project and need two things, a correct coding file and the problem solved by hand.

I have a template made to make the coding easier but I need you to put in the right numbers where the * are in the template

Please provide notes for the mathematical approach (solving by hand)

Please submit a .m file of the code and a separate file for the handwritten work

Here is the template, fill in the blanks where the * are with the correct value:

```% Numerical Integration
% --------------------------Function description--------------------------%
% central_fc():         Calculates central finite difference
% forward_fc():         Calculates forward finite difference
% backward_fc():        Calculates backward finite difference
% trapezoid():          Integration by using Trapezoidal Rule
% simpson():            Integration by using Simpson's 1/3
% ------------------------------------------------------------------------%
clc;
clear all;

% Given data, V
V = [4.1 4.7 5.23;
2.2 2.5 2.7;
1.775 1.995 2.125;
1.35 1.49 1.55;
1.1 1.2 1.24;
0.90 0.99 1.03;
0.79 0.87 0.905;
0.68 0.75 0.78;
0.61 0.675 0.7];

% Given data, P
P = [5;10;15;20;25;30;35;40;45];
T = 400;        % We estimate enthalpy at T = 400 K
n = length(P);  % length of P
col = 2;        % column index of V where T = 400 K
delT = 50;      % temperature increment = 50 K

% Calculate derivative of V by calling FD(Finite Differencing)function
% dVdT = central_fd(*,*,*);
% dVdT = forward_fd(*,*,*);
dVdT = backward_fd(*,*,*);

% Calculate function to be integrated: [V-T*(dV/dT)]
for i = 1:*
*(i) = *(*,*) - T*dVdT(*);
end

% Integrate function B along P
H = trapezoid(P,B);  % by Trapezoidal rule
% H = simpson(P,B);  % by Simpson's 1/3

% Print result
fprintf('Enthalpy, H = %f\n',H);

function [*] = central_fd(*,*,*)
% Input
% x: given data (9x3)
% h: increment (temperature)
% c: column index where T = 400 K
% Output
% dvdt: derivative of v
n = height(x); % n = 9
dvdt = zeros(9,1);
for i = 1:n
dvdt(i) = ( x(i,c+1) - x(i,c-1) ) / ( 2*h );
end
end
function [*] = forward_fd(*,*,*)
% Input
% x: given data (9x3)
% h: increment (temperature)
% c: column index where T = 400 K
% Output
% dvdt: derivative of v
n = height(x); % n = 9
dvdt = zeros(9,1);
for i = 1:n
dvdt(i) = ( x(i,c+1) - x(i,c) ) / ( h );
end
end
function [*] = backward_fd(*,*,*)
% Input
% x: given data (9x3)
% h: increment (temperature)
% c: column index of x where T = 400 K
% Output
% dvdt: derivative of v
n = height(x); % n = 9
dvdt = zeros(9,1);
for i = 1:n
dvdt(i) = ( x(i,c) - x(i,c-1) ) / ( h );
end
end

function [*] = trapezoid(*,*)
% Input
% p: pressure data
% b: function to be integrated [V-T*(dV/dT)]
% Output
% H: result of integration
% ***Note that index of this code starts 1, not 0.
n = length(p);
N = n-1;    % the number of segments

b_sum = 0.0;
for j = 2:N
b_sum = b_sum + b(j);
end

H = (p(n)-p(1)) * (b(1) + 2*b_sum + b(n))/(2*N);

end

function [*] = simpson(*,*)
% Input
% p: pressure data
% b: function to be integrated [V-T*(dV/dT)]
% Output
% H: result of integration
% ***Note that index of this code starts 1, not 0.
n = length(p);
N = n-1;    % the number of segments

% Perform summation of values of even index
b1_sum = 0.0;
for j = 2:2:N
b1_sum = b1_sum + b(j);
end
% Perform summation of values of odd index
b2_sum = 0.0;
for j = 3:2:N-1
b2_sum = b2_sum + b(j);
end

H = (p(n)-p(1)) * (b(1) + 4*b1_sum + 2*b2_sum + b(n))/(3*N);
end
```

### Order this or a similar paper and get 20 % discount. Use coupon: GET20

Posted in Uncategorized