ps10solns

ps10solns - %Engineering 6 Problem 10.1 Solution(Numerical...

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

View Full Document Right Arrow Icon
%Engineering 6, Problem 10.1 Solution %(Numerical integration) %Suppress extra lines in output and set fixed short display format compact; format short; clc; %Clear command window %Trapezoidal method for integral of 1/x from x=2 to x=5 disp( 'Integral of 1/x from x=2 to x=5 using trapezoidal integration:' ); disp( ' ' ); %Three subintervals (i.e., 4 values of x, including 2 and 5) x = linspace(2,5,4); y = 1./x; result = trapz(x,y); %Convert result to a string and display everything on one line % using the disp command. (Note the square brackets.) disp([ 'Result for 3 subintervals is: ' ,num2str(result)]); disp( ' ' ); %Six subintervals (i.e., 7 values of x, including 2 and 5) x = linspace(2,5,7); y = 1./x; result = trapz(x,y); disp([ 'Result for 6 subintervals is: ' ,num2str(result)]); disp( ' ' ); %Twelve subintervals (i.e., 13 values of x, including 2 and 5) x = linspace(2,5,13); y = 1./x; result = trapz(x,y); disp([ 'Result for 12 subintervals is: ' ,num2str(result)]); disp( ' ' ); %Twenty-four subintervals (i.e., 25 values of x, including 2 and 5) x = linspace(2,5,25); y = 1./x; result = trapz(x,y); disp([ 'Result for 24 subintervals is: ' ,num2str(result)]); disp( ' ' ); %Forty-eight subintervals (i.e., 49 values of x, including 2 and 5) x = linspace(2,5,49); y = 1./x; result = trapz(x,y); disp([ 'Result for 48 subintervals is: ' ,num2str(result)]); disp( ' ' ); disp( ' ' );
Background image of page 1

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

View Full DocumentRight Arrow Icon
%Simpson's method for integral of 1/x from x=2 to x=5. % Note: we first have to define a user-defined function for 1/x % in a separate file. Here we have named that file one_over_x.
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 note was uploaded on 01/22/2011 for the course ENG 006 taught by Professor Lagerstrom during the Fall '06 term at UC Davis.

Page1 / 6

ps10solns - %Engineering 6 Problem 10.1 Solution(Numerical...

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