Advertisement
Guest User

Sophie

a guest
Mar 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.80 KB | None | 0 0
  1. % Connor Smith 03 21 2019
  2. % Discretization Exercise
  3. % ((2F matlab codes are the worst don't feel bad))
  4. clc;
  5. clear;
  6. [X,Y] = meshgrid(-0.02:0.0002:0.02,-0.02:0.0002:0.02);
  7. [Ax,Ay] = meshgrid(-0.02:0.0002:0.02,-0.02:0.0002:0.02);
  8. m_Ax = zeros(length(X(1,:)),length(Y(1,:)));
  9. m_Ay = zeros(length(X(1,:)),length(Y(1,:)));
  10. V = zeros(length(X(1,:)),length(Y(1,:)));
  11.  
  12. for i = 1:length(X(1,:))
  13.     for j = 1:length(Y(1,:))
  14.         % Check if it falls within the structure
  15.         r = sqrt(X(i,j)^2 + Y(i,j)^2);
  16.         if (r > 0.01) && (r < 0.02)
  17.             theta = atan(Y(i,j)/X(i,j));
  18.             m_Ax(i,j) = 0.02/r * cos(theta);
  19.             m_Ay(i,j) = 0.02/r * sin(theta);
  20.             V(i,j) = 0.02/r;
  21.         end
  22.     end
  23. end
  24.  
  25. figure(1);
  26. quiver(Ax,Ay,m_Ax,m_Ay);
  27.  
  28. figure(2);
  29. contour(X,Y,V);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement