0

I am trying to implement the following vector calculus equation in MATLAB.

enter image description here

Here n, u, v etc are 2D matrix of size 201 X 201 and others like mu and chi are respective functions. There are few doubts which comes to my mind now. gradient command produces both x-component and y-component. So how can I represent grad(n)? Can someone help me to realize this equation?


My attempt to code the first component alone in the equation is given below. The code is running inside a loop. I believe this nx+ny part in the code is wrong, but I saw such an attempt here in the example section "Part II: Divergence of a Vector Field".

    [U,V] = meshgrid(1:201);
    while t<T-dt
      [nx,ny]=gradient(rho(:,:,1),dx,dy);
      [ux,uy]=gradient(u(:,:,1),dx,dy);
      a = divergence(U,V,mu*(nx+ny));
      %b =divergence((U,V,chi*n(:,:,1)*(ux+uy));
      n(:,:,2) = (dt)*(a) + n(:,:,1);
      t=t+dt
      u(:,:,1) = u(:,:,2);
      n(:,:,1) = n(:,:,2);
      rho(:,:,1) = rho(:,:,2);
    end
Devanand T
  • 63
  • 5

0 Answers0