{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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' );
Image of page 1

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

View Full Document Right Arrow Icon
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' );
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern