hw2_4 - (delta_x(n-1)); %Expression using Central...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
%Song, Hwan %AAE412 %HW2, No.4 % clear all close all clc c n = 2; %Initial Value set up f_prime = 2; f for n = 2:1:15 %Setting up steps delta_x(n-1) = 2^(-n); %Delta_x value at x = 0 in function f x_jm1 = -1.5*delta_x(n-1); %x(j-1) x_j = -.5*delta_x(n-1); %x(j) x_jp1 = .5*delta_x(n-1); %x(j+1) x_jp2 = 1.5*delta_x(n-1); %x(j+2) fx_jm1 = (sin(x_jm1 + sin(x_jm1)))/(1+log(1+tan(x_jm1))); %f(x) at x(j-1) fx_j = (sin(x_j+sin(x_j)))/(1+log(1+tan(x_j))); %f(x) at x(j) fx_jp1 = (sin(x_jp1 + sin(x_jp1)))/(1+log(1+tan(x_jp1))); %f(x) at x(j+1) fx_jp2 = (sin(x_jp2 + sin(x_jp2)))/(1+log(1+tan(x_jp2))); %f(x) at x(j+2) %Expression using Taylor Series fx_12_p_ts(n-1) = ((fx_jm1/24) - (9*fx_j/8)+(9*fx_jp1/8)-(fx_jp2/24))/
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (delta_x(n-1)); %Expression using Central Difference fx_12_p_cd(n-1) = (fx_jp1-fx_j)/delta_x(n-1); %Error when Taylor series is used error_ts(n-1) = abs(fx_12_p_ts(n-1)-f_prime); %Error when Central Defference is used error_cd(n-1) = abs(fx_12_p_cd(n-1)-f_prime); end e loglog(delta_x,error_cd,'r') %Plot Central Difference in loglog scale hold on; loglog(delta_x,error_ts,'b'); %Plot Taylor Series in loglog scale legend('Central Difference Error', 'Taylor Series Error') title('Error vs Delta x by Song, Hwan') xlabel('Delta x') ylabel('Error') grid on g...
View Full Document

This document was uploaded on 10/24/2010.

Ask a homework question - tutors are online