problem2.m - problem 2b 1 P = 1 g(cm*s 1 cP = 0.01 g(cm*s...

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

View Full Document Right Arrow Icon
% problem 2b % 1 P = 1 g/(cm*s); 1 cP = 0.01 g/(cm*s); mu_w = 0.01; mu_o = 0.03; lambda = 1.005; % set how many points will be there for x and t. Nx = 801; Nt = 51; % set up x and t vectors and initialize v matrix using zeroes. x = linspace(10, 0, Nx); dx = x(2) - x(1); t = linspace(0, 5, Nt); dt = t(2) - t(1); v = zeros(Nx, Nt); % set BC and IC to vw and vo. % at x = 0, v = 0 % at x = 10, v = 8 cm/s % at t = 0, v = 0 for 0 <= x < 10; v(1,:) = 8; v(1,1) = 0; v(1, end) = 0; % Find index where x = 6; iter = 0; bool = 1; while (bool == 1 && iter < Nx) iter = iter + 1; if (x(iter) == 6) bool = 0; i6cm = iter; end end % calculate v using equations developed in part a. it = 0; % initial value for iteration maxit = 100; % maximum iteration. The loop should after reaching 100 iterations. tol = 0.005; % Tolerance for the error. err = 100; % initial value for error so the loop can start while (it < maxit && err > tol) it = it + 1; % count iterations vold = v; % save current v values for calculation of new v values % compute v for x in 10cm ~ 6cm using equation (1) from part a for i = 2 : i6cm for j = 2 : Nt - 1 vnew = (-(dx^2/(2*mu_o*dt))*(v(i,j+1) - v(i,j-1)) + v(i+1,j) + v(i- 1,j))/2; v(i,j) = lambda*vnew + (1-lambda)*vold(i, j); end end
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

0/0 PREVIEWS LEFT
Sign up to access 24/7 study resources for your classes

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern