How do you control the end of streamline?
8 views (last 30 days)
Show older comments
Dear friends,
I am plot electric field line between two circle. I want the electric line end at the outer circle.
I can not find a option to achieve the goal.
Your help would be highly appreciated!
% Define radii of circles
r1 = 5; % radius of inner circle
r2 = 10; % radius of outer circle
% Define charge at center
q = 1; % charge
% Define grid for electric field calculations
x = linspace(-r2,r2,50);
y = linspace(-r2,r2,50);
[X,Y] = meshgrid(x,y);
% Define electric field function
Ex = @(x,y) q/(6.2*pi)*x./(x.^2+y.^2).^1.5;
Ey = @(x,y) q/(6.2*pi)*y./(x.^2+y.^2).^1.5;
% Calculate electric field components on grid
U = Ex(X,Y);
V = Ey(X,Y);
% Plot circles
theta = linspace(0,2*pi,100);
xc1 = r1*cos(theta);
yc1 = r1*sin(theta);
xc2 = r2*cos(theta);
yc2 = r2*sin(theta);
plot(xc1,yc1,'k-',xc2,yc2,'k-')
axis equal
% Plot electric field lines
%quiver(X,Y,U,V,'LineWidth',1,'MaxHeadSize',0.5);
streamline(X,Y,U,V,xc1,yc1)
%streamline(X,Y,U,V,xc2,yc2)
0 Comments
Accepted Answer
akshatsood
on 31 Aug 2023
Edited: akshatsood
on 31 Aug 2023
Hi Daniel,
I understand that you have plotted electric field lines between two circles, yet the lines fail to end at the outer circle and extend beyond that. One possible workaround can be modifying the properties of the lines using the dot notation. I am using the variables s1 and s2 to store the handles of streamlines as follows
s1 = streamline(X,Y,U,V,xc1,yc1);
s2 = streamline(X,Y,U,V,xc2,yc2);
To be more clear, if you enter s1 and s2 in the MATLAB command window, it will return a vector of lines which represents each blue line in the streamline plot.
class(s1) % matlab.graphics.primitive.Line
numel(s1) % 100
Now, when I observed both the streamline plots, I found that both have a common part among them which depicts the electric field lines that originate from the outer circle and extend outside. Hence, it would be enough to modify the properties of these lines using the s2 graphics handle. Here is the code snippet for your reference
for i = 1:numel(s2)
s2(i).Color = 'w'; % update the color of line to white
end
I hope this helps.
0 Comments
More Answers (0)
See Also
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!