Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. %source code by:Bijan Binaee <bij@n@binaee.com>
  2. function solenoidII(a)
  3. step = 0.6;
  4. max = 3;
  5. if nargin < 1
  6. a = 0.7;
  7. end
  8. [x,y,z]=meshgrid(-max:step:max,-max:step:max,-max:step:max);
  9. %z=x
  10. U = zeros(size(x));
  11. V = zeros(size(x));
  12. W = zeros(size(x));
  13. s = 0;
  14. for i = 1 : numel(x)
  15. [ U(i) , V(i) , W(i) ] = H_feild (x(i) ,y(i) ,z(i),a);
  16. disp (ceil(i./numel(x) * 100));
  17. H = sqrt ( U(i)^2 + V(i)^2 + W(i) ^ 2 );
  18. if ( H > 3 )
  19. U(i) = U(i) ./ H * 3;
  20. V(i) = V(i) ./ H * 3;
  21. W(i) = W(i) ./ H * 3;
  22. end
  23. s = s + H;
  24. end
  25. disp(s);
  26. [r,theta] = meshgrid(0:a/2:a,linspace(0,2*pi,20));
  27. X = r.*cos(theta);
  28. Y = r.*sin(theta);
  29. Z = X - X;
  30. figure;
  31. surf(X,Y,Z);
  32. hold on
  33. quiver3(x,y,z,U,V,W,2);
  34. hold off
  35. figure;
  36. [sx,sy,sz] = meshgrid(-2.0:0.5:2.0,-2.0:0.5:2.0,0);
  37. streamline(stream3(x,y,z,U,V,W,sx,sy,sz));
  38. view(3);
  39. xlabel('X-axis','fontsize',14);
  40. ylabel('Y-axis','fontsize',14);
  41. uicontrol('style','slider',...
  42. 'position',[150 0 300 20],'Callback',@(hObject, event) updateplot(hObject, event,x,y,z),...
  43. 'value',a, 'min',0, 'max',4);
  44. end
  45.  
  46. function [u ,v, w] = H_feild (x,y,z,r0)
  47. r = sqrt ( x .^ 2 + y .^ 2 + z .^ 2 );
  48. fun = @(t) z.*r0.*cos(t)./((sqrt(r.^2-2.*r0.*(x.*cos(t)+y.*sin(t))+r0.^2)).^3);
  49. u = integral( fun , 0 , 2 .* pi );
  50. fun = @(t) z.*r0.*sin(t)./((sqrt(r.^2-2.*r0.*(x.*cos(t)+y.*sin(t))+r0.^2)).^3);
  51. v = integral( fun , 0 , 2 .* pi );
  52. fun = @(t) r0.^2./((sqrt(r.^2-2.*r0.*(x.*cos(t)+y.*sin(t))+r0.^2)).^3);
  53. w = integral( fun , 0 , 2 .* pi );
  54. fun = @(t) x.*r0.*cos(t)./((sqrt(r.^2-2.*r0.*(x.*cos(t)+y.*sin(t))+r0.^2)).^3);
  55. h1 = integral( fun , 0 , 2 .* pi );
  56. fun = @(t) y.*r0.*sin(t)./((sqrt(r.^2-2.*r0.*(x.*cos(t)+y.*sin(t))+r0.^2)).^3);
  57. h2 = integral( fun , 0 , 2 .* pi );
  58. w = w - h1 - h2;
  59. if ( isnan(w) )
  60. u = 0;
  61. v = 0;
  62. w = 0;
  63. return;
  64. end
  65.  
  66. %{
  67. mag = sqrt ( u^2 + v^2 + w^2);
  68. u = u ./ mag;
  69. v = v ./ mag;
  70. w = w ./ mag;
  71. %}
  72. end
  73.  
  74. function updateplot(hObject,~,x,y,z)
  75. a = round (get(hObject,'Value')) - 0.1;
  76. U = zeros(size(x));
  77. V = zeros(size(x));
  78. W = zeros(size(x));
  79. for i = 1 : numel(x)
  80. [ U(i) , V(i) , W(i) ] = H_feild (x(i) ,y(i) ,z(i),a);
  81. disp (ceil(i./numel(x) * 100));
  82. end
  83. figure;
  84. [r,theta] = meshgrid(0:a,linspace(0,2*pi,20));
  85. X = r.*cos(theta);
  86. Y = r.*sin(theta);
  87. Z = X - X;
  88. surf(X,Y,Z);
  89. hold on;
  90. quiver3(x,y,z,U,V,W,2);
  91. disp(a);
  92. drawnow;
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement