{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Math 112 Matlab #1

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

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

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.

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

View Full Document
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); fprintf(' Left-endpoint approximation = %f.\n',IL); fprintf('Right-endpoint approximation = %f.\n',IR); fprintf(' Trapezoidal approximation = %f.\n',IT);
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online