{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw1 - function y=problem_3_1(x,nterms%Problem 3.1 cosx=0...

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

function y=problem_3_1(x,nterms) %Problem 3.1 % cosx=0; i=1; cosxtrue=cos(x); disp( 'order true value approximation error' ); while i<=nterms n=2*i-2; fact=(-1)^(i-1)*x^n/factorial(n); cosx=cosx+fact; perror=((cosxtrue-cosx)/cosxtrue)*100; fprintf( '%2d %11.10f %11.10f %12.8f\n' ,i,cosxtrue,cosx,perror); i=i+1; end function run in matlab EDU>> problem_3_1(1.5,8) order true value approximation error 1 0.0707372017 1.0000000000 -1313.68329030 2 0.0707372017 -0.1250000000 276.71041129 3 0.0707372017 0.0859375000 -21.48840776 4 0.0707372017 0.0701171875 0.87650367 5 0.0707372017 0.0707528251 -0.02208652 6 0.0707372017 0.0707369341 0.00037823 7 0.0707372017 0.0707372050 -0.00000469 8 0.0707372017 0.0707372016 0.00000004

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

View Full Document
function y=tankvolume(R,d) % Problem 3.5 if d<=(3*R) if d<=R cone=((1/3))*(pi)*(d^2)*d; fprintf( '%8.4f\n' ,cone); end if d>R x=(pi*((R)^2)*(d-R))+(.3333333333)*pi*(R^3); fprintf( '%8.4f\n' ,x); end end if d>(3*R) disp( 'overtop' ); end end Function tankvolume run in matlab EDU>> tankvolume(1.5,1) 1.0472 EDU>> tankvolume(1.5,2) 7.0686 EDU>> tankvolume(1.5,4.5) 24.7400 EDU>> tankvolume(1.5,4.6) overtop function problem3_9
%Problem 3.9 % %U=velocity(m/s),S=channel slope, n=roughness %coeficient, B=width(m), and H=depth(m) disp( ' n S B H U' ); j=1; matrix=[.035 .0001 10 2; .020 .0002 8 1; .015 .0010 20 1.5; .030 .0007 24 3; .022 .0003 15 2.5]; % while j~=6 % U=(sqrt(matrix(j,2))/matrix(j,1))*((matrix(j,3)*matrix( j,4))/(matrix(j,3)+2*matrix(j,4)))^(2/3); % fprintf( '%4.3f %5.4f %4.2f %3.2f %5.4f\n' , matrix(j,1),matrix(j,2),matrix(j,3),matrix(j,4),U); % j=j+1; % end end Program run in matlab EDU>> problem3_9 n S B H U 0.035 0.0001 10.00 2.00 0.3624 0.020 0.0002 8.00 1.00 0.6094 0.015 0.0010 20.00 1.50 2.5167 0.030 0.0007 24.00 3.00 1.5809 0.022 0.0003 15.00 2.50 1.1971 function y=SquareRoot(x,e) % Problem 3.13

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

View Full Document
y_old=0; y=x; error=1; while error>=e if x==0 y=0; break end if x<0 while error>=e y=(y+-x/y)/2;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 19

hw1 - function y=problem_3_1(x,nterms%Problem 3.1 cosx=0...

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

View Full Document
Ask a homework question - tutors are online