logo

Estimate dh/dt Assignment 2022

   

Added on  2022-10-14

23 Pages3294 Words15 Views
PART: 2
1. Estimate the value of dh/dt at log entry 3 using backward, forward and central
differences.
Central difference = df(x)/dx=f(x+h)−f(xh)/2h,
Forward difference = df(x)/dx=f(x+h)−f(x)/ h,
Backward difference = df(x)/dx=f(x)−f(xh)/ h
2. Repeats Requirement 1 and verifies the results.
Fun = @(x) exp(-x).*sin(3*x);
dFun = @(x) -exp(-x).*sin(3*x)+ 3*exp(-x).*cos(3*x);
x=linspace(0,4,101);
F=Fun(x);
h=x(2)-x(1);
xCentral=x(2:end-1);
dFCenteral=(F(3:end)-F(1:end-2))/(2*h);
xForward=x(1:end-1);
dFForward=(F(2:end)-F(1:end-1))/h;
xBackward=x(2:end);
dFBackward=(F(2:end)-F(1:end-1))/h;
plot(x,dFun(x));
hold on
plot(xCentral,dFCenteral,'r')
plot(xForward,dFForward,'k');
plot(xBackward,dFBackward,'g');
legend('Analytic','Central','Forward','Backward')

3. Estimates dh/dt for the entire data set from Assignment 1 using backward, forward and
central differences (only calculated at the start or end for those differences which are
possible).
For forward differences:
At starting point:
X = 0.16,
Y= 1.7197
At ending point:
X = 2.44,
Y= 0.041054
For Central differences:
At starting point:

X = 0.2,
Y= 1.7197
At ending point:
X = 2.52,
Y= 0.0084
For Backward differences:
At starting point:
X = 0.8,
Y= 2.6102
At ending point:
X = 2.56,
Y= -0.02175
4. Plots the results for Requirement 3.

5. Discuss which is the best result out of the backward, forward and central differences and
Why.
Central difference is more preferable than the backward in forward differences. Some of
the main reason of it is mentioning below:
The central difference scheme is in the second order of h for smooth f, however
the other two is being mentioned in first order of h. The real space error for the
central difference scheme is O(h2) at the time of smooth f whereas for the forward
and the backward scheme it would be O(h). Hence the central difference will have
a better error rather than other two, at the fixed sufficient h.
Central differences use the points at same numbers rather than other two, by
which there will be no loss in efficiency.
6. Determines the first instant the magnitude of the rate of descent for the central difference
became lower than the value in Eq. (1).
dh /dt = 10 + 4×6.7131 ft/s
At, X= 0.12,
Y= 2.3253

7. Estimates the accelerations in the vertical direction by:
(a) Taking the central difference of the central difference from Requirement 3;
Central Difference:
X = 2
Y= 0.43628
(b) Directly calculating the second derivative.
close all; clear all;
f=@(x) sin(x); x0=0.5;
ed2f=@(x) -sin(x);
dx=[0.5:-0.1:0.1,0.05,0.01,0.005,0.001]; N=length(dx);
d2f=zeros(1,N); Err = zeros(1,N);
for i=1:N
fL=f(x0-dx(i)); f0=f(x0); fR=f(x0+dx(i));

d2f(i)=(fL-2*f0+fR)/dx(i)^2;
Err(i)=100*abs((d2f(i)-ed2f(x0))/ed2f(x0));
end
semilogx(dx,d2f,'b--o',dx,ed2f(x0)*ones(1,N),'m');
legend('Approximate','Exact');
xlabel('\Delta x'); ylabel('d^2f(0.5)/dx^2')
disp('Press any key')
pause
loglog(dx,Err,'bo'); hold on
xlabel('\Delta x'); ylabel('Percentage error')
coef=polyfit(log10(dx),log10(Err),1);
loglog(dx([1,end]),10^coef(2)*dx([1,end]).^coef(1),'m');
8. Has appropriate comments throughout.

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Transient analysis stability and surge protection Solution 2022
|13
|1513
|19