{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Homework 5 - A Backward Finite D 40 20 0 y-20-40-60-80...

This preview shows pages 1–3. Sign up to view the full content.

A) 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 -80 -60 -40 -20 0 20 40 60 80 x y Backward Finite Difference Real .25 .1 .05 .025 clear; hValues = [.25 .1 .05 .025]; xValues = [0:.01:1]; y = inline( '(4*x^5-3*x^4+5*x^3+x^2-7)*sin(3*pi*x)' ); realDy = inline( '(20*x^4-12*x^3+15*x^2+2*x)*sin(3*pi*x)+(4*x^5- 3*x^4+5*x^3+x^2-7)*3*pi*cos(3*pi*x)' ); xIndex = 1; for x = xValues dy(1, xIndex) = realDy(x); xIndex = xIndex + 1; end hIndex = 2; for h = hValues xIndex = 1; for x = xValues dy(hIndex, xIndex) = 1/h * (y(x) - y(x-h)); xIndex = xIndex + 1; end hIndex = hIndex + 1; end plot(xValues, dy(1,:), xValues, dy(2,:), xValues, dy(3,:), xValues, dy(4,:), xValues, dy(5,:)); xlabel( 'x' ); ylabel( 'y' ); title( 'Backward Finite Difference' ); legend( 'Real' , '.25' , '.1' , '.05' , '.025' );

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 -80 -60 -40 -20 0 20 40 60 80 x y Forward Finite Difference Real .25 .1 .05 .025 clear; hValues = [.25 .1 .05 .025]; xValues = [0:.01:1]; y = inline( '(4*x^5-3*x^4+5*x^3+x^2-7)*sin(3*pi*x)' ); realDy = inline( '(20*x^4-12*x^3+15*x^2+2*x)*sin(3*pi*x)+(4*x^5- 3*x^4+5*x^3+x^2-7)*3*pi*cos(3*pi*x)' ); xIndex = 1; for x = xValues dy(1, xIndex) = realDy(x); xIndex = xIndex + 1; end hIndex = 2; for h = hValues xIndex = 1; for x = xValues dy(hIndex, xIndex) = 1/h * (y(x+h) - y(x)); xIndex = xIndex + 1; end hIndex = hIndex + 1; end plot(xValues, dy(1,:), xValues, dy(2,:), xValues, dy(3,:), xValues, dy(4,:), xValues, dy(5,:)); xlabel( 'x' );
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern