The code below will create a vector x (1000 points long) between 0 and 2pi. It t
ID: 3815181 • Letter: T
Question
The code below will create a vector x (1000 points long) between 0 and 2pi. It then calculates a "noisy" sin (x) by adding small random numbers to it. Your job is as follow: A) Differentiate the data (dy/dx) (call it dydx) A2) Differentiate the data with higher-order eqn (call it dydx_high) B) Curve fit the data (use any method you like) (call it y2) C) Differentiate the curve fit you just created (call it dy2dx) D) Numerically Integrate the data (call it int y) E) Plot the following: x vs. y (do this on a different subplot than the others) dydx (do the next 3 on the same subplot) dy2dx negative of numerical integral of y (-1*int_y) Make sure you add appropriate titles, legends, labels, etc x = linspace(0, 2*pi, 1000); y = sin(x) + rand size (x))*0. 01; y(1) = 0; %force it to start at 0.Explanation / Answer
A) dydx = diff(y(:))./diff(x(:));
A2) eqn = 'd4y - 2*d2y + dy = t^3 +2*exp(t)'
dxdy_high=dsolve(eqn)
%The notation d4y means the 4th derivative of y, dky means the kth derivative (where k is a positive integer).We can solve %this equation with the command dsolve
B) y2=fit(dydx,dydx_high,'poly2')
%poly2 is the fittype(can customize it to the type one wishes)
C) dy2dx = diff(y2(:))./diff(x(:));
D) int_y = trapz(dy2dx)
%trapz returns the final integration value. cumtrapz can be used to return intermediate values in a vector
E) subplot(3,1,1) %First Subplot
plot(x,y) %plot x vs y
subplot(3,1,2) %SecondSubplot
plot(y(1:end-dydx) %plot dydx
plot(y2(1:end-dy2dx,'--') %plotdy2dx
plot(-1*int_y,'c*') %plot negative of int_y