How to pull specific data from solution set?
Show older comments
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)))];
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations 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!