Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Finite Difference Method 2- The displacement of a vehicle (x) is given below as

ID: 644104 • Letter: F

Question

Finite Difference Method

2- The displacement of a vehicle (x) is given below as a function of time t.

Write a MATLAB code to find the velocity and acceleration of the vehicle as a function of time, using FDM. Your results must be 2nd-order accurate at all time nodes. Present your results in a tabular form. Hint: velocity=dx/dt, and acceleration=d2 x/dt2 .

I'm lost on how to go about this one. I think I am over thinking it.

%% Question 2: FDM for Vel and Accel

clear;clc;
t=([0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0])';
x1=0.0000;x2=0.8733;x3=1.8224; x4=2.8611; x5=4.0032; x6=5.2625; x7=6.6528; x8=7.9935; x9=9.5213; x10=10.8163; x11=12.5789;
x=([x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11])';

app1=zeros(1,11);
app2=zeros(1,11);
for i=1:10
for j=1:i-1
app1(i)=app1(i)+((-x(j+2)+4*(x(j+1))-3*(x(j)))/(2*(t(j+2)-t(j))))+(t(j+2)-t(j))^2;
%app2(i)=app2(i)+((x(j+1)-(x(j-1))))/(2*(t(j+2)-t(j)))+(t(j+2)-t(j))^2
end
end
v=app1';
for i=1:9
for j=1:i-1
app2(i)=app2(i)+((-v(j+3)+4*(v(j+2))-5*(v(j+1)+2*(v(j)))/((t(j+2)-t(j)))^2))+(t(j+2)-t(j))^2;
%app2(i)=app2(i)+((x(j+1)-(x(j-1))))/(2*(t(j+2)-t(j)))+(t(j+2)-t(j))^2
end
end
a=app2';
disp(' t x v');
disp([t,x,v,a]);

t x 0.0 0 0.1 0.8733 0.2 1.8224 0.3 2.8611 0.4 4.0032 0.5 5.2625 0.6 6.6528 0.7 7.9935 0.8 9.5213 0.9 10.8163 1.0 12.5789

Explanation / Answer

if (datain_type < 1 || datain_type > 3) error('Value for datain_type must be a 1, 2 or 3'); elseif (dataout_type < 1 || dataout_type > 3) error('Value for dataout_type must be a 1, 2 or 3'); end % Determine Number of points (next power of 2), frequency increment % and Nyquist frequency N = 2^nextpow2(max(size(datain))); df = 1/(N*dt); Nyq = 1/(2*dt); % Save frequency array iomega_array = 1i*2*pi*(-Nyq : df : Nyq-df); iomega_exp = dataout_type - datain_type; % Pad datain array with zeros (if needed) size1 = size(datain,1); size2 = size(datain,2); if (N-size1 ~= 0 && N-size2 ~= 0) if size1 > size2 datain = vertcat(datain,zeros(N-size1,1)); else datain = horzcat(datain,zeros(1,N-size2)); end end % Transform datain into frequency domain via FFT and shift output (A) % so that zero-frequency amplitude is in the middle of the array % (instead of the beginning) A = fft(datain); A = fftshift(A); % Convert datain of type datain_type to type dataout_type for j = 1 : N if iomega_array(j) ~= 0 A(j) = A(j) * (iomega_array(j) ^ iomega_exp); else A(j) = complex(0.0,0.0); end end % Shift new frequency-amplitude array back to MATLAB format and % transform back into the time domain via the inverse FFT. A = ifftshift(A); datain = ifft(A); % Remove zeros that were added to datain in order to pad to next % biggerst power of 2 and return dataout. if size1 > size2 dataout = real(datain(1:size1,size2)); else dataout = real(datain(size1,1:size2)); end return
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote