Question

Problem 1. Consider the harmonic function 2 cos 3x 1xs5 Investigate the validity of the numerical differentiation process by

0 0
Add a comment Improve this question Transcribed image text
Answer #1

%%%bMatlab code %%

clc;
close all;
syms x;
y=2*cos(3*x)/x;
dy=diff(y);
N1=11;
N2=101;
a=1;
b=5;
h1=(b-a)/(N1-1);
h2=(b-a)/(N2-1);
x1=a:h1:b;
x2=a:h2:b;
for n=1:length(x1)-1
D1y(n)=double((subs(y,x1(n+1))-subs(y,x1(n)))/h1);
end
for n=1:length(x2)-1
D2y(n)=double((subs(y,x2(n+1))-subs(y,x2(n)))/h2);
end

Dyy=double(subs(dy,x2));

figure;
plot(x2,Dyy);
hold on
plot(x1(1:end-1),D1y,'-*');
hold on
plot(x2(1:end-1),D2y,'-o');
legend('Exact derivative','Using N=11','Using N=101');
grid on
fprintf(' Exact Derivative at x=1.6 is = %f \n' ,double(subs(dy,1.6)));
fprintf(' Using N=11 Derivative = %f \n ',D1y(3));

fprintf(' Exact Derivative at x=2 is = %f \n',double(subs(dy,2)) );
fprintf(' Using N=101 Derivative is = %f \n ',D2y(26));

OUTPUT:

5 Exact derivative Using N-11 Using N 101 4 2 1 0 1 -2 -3 5 1 2,5 3 3.5 4 1.5 2 4.5 LC LC

Exact Derivative at x=1.6 is = 3.667259
Using N=11 Derivative = 0.396584   
Exact Derivative at x=2 is = 0.358161
Using N=101 Derivative is = 0.179929

Add a comment
Know the answer?
Add Answer to:
Problem 1. Consider the harmonic function 2 cos 3x 1xs5 Investigate the validity of the numerical...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT