3D Plot of 2D sim

2 ビュー (過去 30 日間)
Jamie Al
Jamie Al 2021 年 2 月 3 日
編集済み: Jamie Al 2022 年 1 月 19 日
I have the following code. The code works for me now and it provides a 2D plot, however I am trying to plot a 3D plot. So an example would be like this:
Do you have sugesstions to do this in MATLAB? Thanks
Code:
%Start setting up constants
% Compute the cyclotron frequency and radius (Larmor radius)
omega = (charge .*B(3)) ./mass;
rL = v(2) ./omega; % try v(2) as well since initial v is the perp velocity to B
X = zeros(n,3); % initialize an array of zeros with size nx3 for positions
for time = 1:1:n
%compute the t vector
%compute the s vector
% start the Boris algorithm:
% First half E acceleration: generally for E =/0 ande B =/0
% First half B rotation
% Second hald B rotation
% Second half E acceleration
% Finally update position
end
% plotting
figure;
plot(X(:,1),X(:,2),'k','Linewidth',2); hold on;
set(gca,'TickLabelInterpreter','Latex','Fontsize',14)
ylabel('$ y / d_{\rm p} $','Interpreter','Latex','Fontsize',14);
xlabel('$ x / d_{\rm p} $','Interpreter','Latex','Fontsize',14);

採用された回答

David Goodmanson
David Goodmanson 2021 年 2 月 3 日
編集済み: David Goodmanson 2021 年 2 月 3 日
Hi Lujain,
After setting v = [0 1 1] to provide some initial z velocity,
figure(2)
plot3(X(:,1),X(:,2),X(:,3))
grid on
and note that if you put the mouse cursor inside the window and click on the symbol with the circle enclosing the cube, you can rotate the plot with a click-hold mouse.
  1 件のコメント
Jamie Al
Jamie Al 2021 年 2 月 3 日
Hello David!
Thanks a lot, this does work!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by