Homework 5 - A Backward Finite D 40 20 0 y-20-40-60-80 Real.25.1.05.025 0 0.1 0.2 0.3 0.4 0.5 x 0.6 0.7 0.8 0.9 1 clear hValues =.25.1.05.025

Info iconThis 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' );
Background image of page 1

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

View Full DocumentRight Arrow Icon
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,:));
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 04/17/2008 for the course BMED 2200 taught by Professor Robertspilker during the Spring '08 term at Rensselaer Polytechnic Institute.

Page1 / 8

Homework 5 - A Backward Finite D 40 20 0 y-20-40-60-80 Real.25.1.05.025 0 0.1 0.2 0.3 0.4 0.5 x 0.6 0.7 0.8 0.9 1 clear hValues =.25.1.05.025

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online