homworkfive

# homworkfive - x=linspace(0,Lx,nxp); x for is=1:1 for...

This preview shows page 1. Sign up to view the full content.

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;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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); 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 %...
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.

Ask a homework question - tutors are online