필터 지우기
필터 지우기

How to pull specific data from solution set?

조회 수: 1 (최근 30일)
Tom Keaton
Tom Keaton 2018년 10월 31일
댓글: Tom Keaton 2018년 11월 1일
Hello, I am using this ODE solver and I am trying to figure out how I can reference the velocity components of the matrix of solutions. I think I would know how to pull the position components given the assigned variables below because the matrix "W" contains them, but how may I be able to define a velocity matrix of solutions? For context, I am solving the Lorentz force equations. The x, y and z and vx, vy and vz components are predefined and can be completely random. The "vparts" and "sparts" are the velocity and position components of arrays.
Main Script:
[X,Y,Z] = meshgrid(-0.5:.01:0.5,-0.5:.01:0.5,-0.5:.01:0.5);
[Bx, By, Bz] = B_test();
Bfieldx = arrayfun(Bx,X,Y,Z);
Bfieldy = arrayfun(By,X,Y,Z);
Bfieldz = arrayfun(Bz,X,Y,Z);
icv = [x; y; z; vx; vy; vz];
%Time Span (sec)
tspan = [0 tstep];
[T,W] = ode15s(@bdipuniodefun, tspan, icv);
[rownum,colnum] = size(W);
plot3(W(:,1), W(:,2), W(:,3), '-r', 'LineWidth',2,'color',[randi(0:1) randi(0:1) randi(0:1)])
xlabel 'x';
ylabel 'y';
zlabel 'z';
grid on
%Redfine the velocity and position components to reference on next if-loop run
vparts(1) = vx;
vparts(2) = vy;
vparts(3) = vz;
sparts(1) = W(rownum,1);
sparts(2) = W(rownum,2);
sparts(3) = W(rownum,3);
B_Test:
function [Bx, By, Bz] = B_test()
syms x y z
mu_0_red = 10E-7;
m = [0,0,1.28];
r = [x, y, z];
B = mu_0_red *(((dot(m,r)*r*3)/norm(r)^5) - m/norm(r)^3);
Bx = matlabFunction(B(1));
By = matlabFunction(B(2));
Bz = matlabFunction(B(3));
bdipolefun:
function bdip = bdipuniodefun(t,s)
%Using SI units
q = 1.60217662E-19;
m_e = 9.11E-31;
[Bx, By, Bz] = B_test();
bdip = [s(4); s(5); s(6); (q/m_e)*(s(5)*Bz(s(1),s(2),s(3)) - s(6)*By(s(1),s(2),s(3))); (q/m_e)*(s(6)*Bx(s(1),s(2),s(3)) - s(4)*Bz(s(1),s(2),s(3))); (q/m_e)*(s(4)*By(s(1),s(2),s(3)) - s(5)*Bx(s(1),s(2),s(3)))];

채택된 답변

Bruno Luong
Bruno Luong 2018년 10월 31일
What prevent you to use bdipuniodefun() to compute the velocity dW/dt from T and W ?
  댓글 수: 8
Bruno Luong
Bruno Luong 2018년 11월 1일
Evidently yes
Tom Keaton
Tom Keaton 2018년 11월 1일
I just manually checked each component and this is true. I wasn't sure how this output of solutions looked so thank you for clarifying that.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by