project2 - +x(j+1))/2)+w(i,x(j+1))); end V(i,k+1) = V(i,1)...

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

View Full Document Right Arrow Icon
N = 1000; L = 10; h = L/(N-1); x = linspace(0,L,1000); o = [5, 1, 0.1, 0.001]; V = zeros(length(o),length(x)); M = zeros(length(o),length(x)); for k = 1:length(o) for i = 1:length(x) w(k,i) = 10.*exp((-((x(i))-5).^2)./(2.*o(k))); end end % Initial condition V(x) for i=1:length(o) for k=1:(length(x)-1) V(i,1) = V(i,1) + (h/6)*(w(i,k)+4*(1/2)*(w(i,k)+w(i,k+1))+w(i,k+1)); end end % Initial condition M(x) for i=1:length(o) for k=1:(length(x)-1) M(i,1) = M(i,1) + (h/6)*(-x(k)*w(i,x(k))-((x(k)+x(k+1))/2)*4*w(i,(x(k) +x(k+1))/2)-x(k+1)*w(i,x(k+1))); end end % Get rest of V(x) for i=1:length(o) for k=1:(length(x)-1) for j=1:k V(i,k+1) = V(i,k+1) + (h/6)*(w(i,x(j))+4*w(i,(x(j)
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: +x(j+1))/2)+w(i,x(j+1))); end V(i,k+1) = V(i,1) + V(i,k+1); end end % Get rest of M(x) for i=1:length(o) for k=1:(length(x)-1) for j=1:k M(i,k+1) = M(i,k+1) + (h/6)*(V(i,j)+4*(1/2)*(V(i,j)+V(i,j+1)) +V(i,j+1)); end M(i,k+1) = M(i,1) + M(i,k+1); end end hold on title('V(x) for various sigma') xlabel('x') ylabel('w(x)') plot(x,V(1,:),'b') plot(x,V(2,:),'r') plot(x,V(3,:),'g') plot(x,V(4,:),'m') figure hold on title('M(x) for various sigma') xlabel('x') ylabel('M(x)') plot(x,M(1,:),'b') plot(x,M(2,:),'r') plot(x,M(3,:),'g') plot(x,M(4,:),'m')...
View Full Document

This note was uploaded on 02/18/2010 for the course ENGINEERIN 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 2

project2 - +x(j+1))/2)+w(i,x(j+1))); end V(i,k+1) = V(i,1)...

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