4. Use the first derivative functions to estimate the dy/dx value for y=sin(x) a
ID: 2074964 • Letter: 4
Question
4. Use the first derivative functions to estimate the dy/dx value for y=sin(x) at x=pi/3. Use a step size (delta x) of pi/10. Compute the magnitude of the error for each approximation (backward, forward, centered).
5. Repeat problem 4 using a step size (delta x) of pi/20. What effect does halving the step size have on each of the errors.
I NEED THIS SOLVED IN MATLAB!!!
Use the first derivative functions to estimate the dy/dx value for y=sin(x) at x=pi/3. Use a step size (delta x) of pi/10. Compute the magnitude of the error for each approximation (backward, forward, centered) 4.Explanation / Answer
The MATLAB program for the given problem is as follows
clc
clear all
x=pi/3;
y=sin(x);
dya=cos(x);
i=pi/3;
j=pi/3+pi/10;
k=pi/3-pi/10;
dyf1=(sin(j)-sin(i))/(j-i);
dyb1=(sin(i)-sin(k))/(i-k);
dyc1=(sin(j)-sin(k))/(j-k);
erf1=dya-dyf1
erb1=dya-dyb1
erc1=dya-dyc1
p=pi/3;
q=pi/3+pi/20;
r=pi/3-pi/20;
dyf2=(sin(q)-sin(p))/(q-p);
dyb2=(sin(p)-sin(r))/(p-r);
dyc2=(sin(q)-sin(r))/(q-r);
erf2=dya-dyf2
erb2=dya-dyb2
erc2=dya-dyc2
Program Explanation:
command
x=pi/3; defines x value as pie/3.
y=sin(x); calcullates sinx value at x=pie/3 and assigns it to y
dya=cos(x); calculates first accurate derivate of y i.e cosx and assigns it to dya
i=pi/3; assigns value of pie/3 to i
j=pi/3+pi/10; assigns value of pie/3+pie/10 to j
k=pi/3-pi/10; assigns value of pie/3-pie/10 to k
dyf1=(sin(j)-sin(i))/(j-i); calculates forward difference approximation of dy/dx for a step size of pie/10 and assigns it to dyf1
dyb1=(sin(i)-sin(k))/(i-k); calculates backward difference approximation of dy/dx for a step size of pie/10 and assigns it to dyb1
dyc1=(sin(j)-sin(k))/(j-k); calculates centered difference approximation of dy/dx for a step size of pie/10 and assigns it to dyc1
erf1=dya-dyf1; calculates error in forward difference approximation method for a step size of pie/10
erb1=dya-dyb1; calculates error in backward difference approximation method for a step size of pie/10
erc1=dya-dyc1; calculates error in centred difference approximation method for a step size of pie/10
p=pi/3; assigns value of pie/3 to p
q=pi/3+pi/20; assigns value of pie/3+pie/20 to q
r=pi/3-pi/20; assigns value of pie/3-pie/20 to r
dyf2=(sin(q)-sin(p))/(q-p); calculates forward difference approximation of dy/dx for a step size of pie/20 and assigns it to dyf2
dyb2=(sin(p)-sin(r))/(p-r); calculates backward difference approximation of dy/dx for a step size of pie/20 and assigns it to dyb2
dyc2=(sin(q)-sin(r))/(q-r); calculates centered difference approximation of dy/dx for a step size of pie/20 and assigns it to dyc2
erf2=dya-dyf2; calculates error in forward difference approximation method for a step size of pie/20
erb2=dya-dyb2; calculates error in backward difference approximation method for a step size of pie/20
erc2=dya-dyc2; calculates error in centred difference approximation method for a step size of pie/20
Finally the result is
erf1 = 0.1431; erb1 = -0.1267; erc1 = 0.0082
erf2 =0.0699; erb2 = -0.0658; erc2 = 0.0021
Effects of using step sizes of pie/10 and pie/20:
1) The errors obtained in forward and backward difference approximation methods are nearly same except sign but the error obtained in centered approximation method is very less, nearly 16 times less in first case and 33 times less in second case compared to forward and backward.
2) Using a step size of pie/20 compared to pie/10 nearly reduces error to 1/2 in forward and backward approximation methods and 1/4th in centered approximation method.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.