Math 112 Matlab #1

Math 112 Matlab #1 - Ashay Mehta Math 112 Calculus II...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Ashay Mehta Math 112 Calculus II Matlab Assignment #1 Professor Levy While N=10 Code: a= -1; b= 5; N = 10; h=(b-a)/N; x=[a:h:b]; %creates a vector of n+1 evenly spaced points f=exp(2*x); IL=0; IR=0; IT=0; for k=1:N; %Note that the vector f has (N+1) elements IL=IL+f(k); IR=IR+f(k+1); IT=IT+(f(k)+f(k+1))/2; end; IL=IL*h; IR=IR*h; IT=IT*h; fprintf(' When N = %i, we find:\n',N); fprintf(' Left-endpoint approximation = %f.\n',IL); fprintf('Right-endpoint approximation = %f.\n',IR); fprintf(' Trapezoidal approximation = %f.\n',IT); % Output from this program: Output: When N = 10, we find: Left-endpoint approximation = 5696.177700. Right-endpoint approximation = 18911.975975. Trapezoidal approximation = 12304.076837. While N=100 Code: a= -1; b= 5; N = 100; h=(b-a)/N; x=[a:h:b]; %creates a vector of n+1 evenly spaced points f=exp(2*x); IL=0; IR=0; IT=0; for k=1:N; %Note that the vector f has (N+1) elements IL=IL+f(k); IR=IR+f(k+1); IT=IT+(f(k)+f(k+1))/2; end; IL=IL*h; IR=IR*h; IT=IT*h; fprintf(' When N = %i, we find:\n',N);...
View Full Document

This note was uploaded on 06/02/2010 for the course MGMT 121 taught by Professor Morozova during the Spring '10 term at NJIT.

Page1 / 4

Math 112 Matlab #1 - Ashay Mehta Math 112 Calculus II...

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