MATLAB

profileSA 11
num_int_ex_simple.m

% numerical integration example using trap rule. function [D] = num_int_ex_simple() % givens t1 = 0; tf = 50; % plot the function t_plot = [t1:.01:tf]'; V = vel(t_plot); plot(t_plot,V); %% calculate distance using num int for one value of N N = 32; % note N is the number of segments, want N+1 base points t = linspace(t1,tf,N+1)'; % for loop h = (tf-t1)/N; D = vel(t1); % calculate f(x1) for j=2:N D = D + 2*vel(t(j)); % + 2*f(x_j) end D = D + vel(tf); % + f(x_n+1) D = D*h/2; end function [V] = vel(t) g=9.81; m=70; c = 12.5; V = g*m/c*(1-exp(-c/m.*t)); end