homworkfive

homworkfive - p=a\b'; peak=p(nx/2+1); plot(x,p); hold on;...

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

View Full Document Right Arrow Icon
clc;clear nx=5;Lx=6;Ly=6; a(Lx,Ly)=0; a(2,1)=700; for iter=1:50 for i=2:nx for j=2: nx a(i,j)=.25*(a(i-1,j)+a(i,j-1)+a(i+1,j)+a(i,j+1)); end end sum=a(5,3)+a(4,3)+a(2,4); sum a a(6,3)=400 sum end e %% Population Problem % Find s1 such that P(7), the population of the 7th town, is 23K clc; clear Lx=20; nx=20; dx=Lx/nx; dxs=dx*dx; nxp=nx+1; c1=20; p(1)=70; p(nxp)=10; a(nxp,nxp)=0; b(nxp)=0; x=linspace(0,Lx,nxp); x for is=1:1 for iter=1:50 s1=dx/p(is); s2=s1(is)*dx/c1; a(1,1)=1; b(1)=p(1); for i=2:nx a(i,i-1)=-1; a(i,i)=2+s2; a(i,i+1)=-1; end a(nxp,nxp)=1; b(nxp)=p(nxp);
Background image of page 1

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

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

Unformatted text preview: p=a\b'; peak=p(nx/2+1); plot(x,p); hold on; xlabel('distance'); ylabel('populations of towns') end end e %% 3 cable problem % Lx=1;nx=20; dx=Lx/nx; dxs=dx*dx; nxp=nx+1; lambda=1; f(1)=0;f(nxp)=0;a(nxp,nxp)=0; b(nxp)=0; x=linspace(0,Lx,nxp); for i=1:nxp x(i)=(i-1)*dx; f(i)=0; end for iter=1:20 a(1,1)=1;b(1)=0; for i=2:nx sour=sqrt(1+(-f(i-1)+f(i+1)/2*dx)^2); a(i,i-1)=1; a(i,i)=-2; a(i,i+1)=1; b(i)=lambda*sour*dxs; end a(nxp,nxp)=1;b(nxp)=0; f=a\b' end integ1=trapz(x,f) integ2=trapz(x, (sour^2)-1)...
View Full Document

This note was uploaded on 02/13/2011 for the course ENME 361 taught by Professor Yoo during the Spring '11 term at Maryland.

Page1 / 2

homworkfive - p=a\b'; peak=p(nx/2+1); plot(x,p); hold on;...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online