I solved a system of differential equations using dsolve. In my solutions i got how my x,y and z variables behave,but I need to plot this as the position vector r=x+y+z through time. how do i get the input t into my solution soi can get a value for each point and plot my position.

1 commentaire

the varibles I got into my function are:(2,0.5,0.5,0.5,1,1,1,1,1,1), just if anyone wants to run the ode solver

Connectez-vous pour commenter.

 Réponse acceptée

KSSV
KSSV le 12 Sep 2018
function botella_magnetica(a,k,m,q,x0,y0,z0,vx0,vy0,vz0)
x=x0;
y=y0;
z=z0;
vx=vx0;
vy=vy0;
vz=vz0;
V=[vx,vy,vz];
R=[x,y,z];
h=animatedline;
if abs(x0) > abs(a * 0.9)
disp('Fuera de zona de analisis')
return
end
grid on;
set(gca, 'XLim',[-100,100], 'YLim',[-100,100],'ZLim',[-100,100]);
k1 = (k * a^(3/2))/(((x+a)^2 + y^2 + z^2)^2);
k2 = (k * a^(3/2))/(((x-a)^2 + y^2 + z^2)^2);
Bx = ((x+a) * k1) - ((x-a) * k2);
By = (y * k1) - (y * k2);
Bz = (z * k1) - (z * k2);
B = [Bx,By,Bz];
Ac = (q/m).*(cross(V,B));
syms u(t) v(t) w(t);
eqn = [diff(u,t,2) == diff(v,t)*Bz - diff(w,t)*By, diff(v,t,2) == diff(w,t)*Bx - diff(u,t)*Bz, diff(w,t,2) == diff(u,t)*By - diff(v,t)*Bx];
Dx = diff(u,t); Dy = diff(v,t); Dz = diff(w,t);
cond = [u(0)==x0, v(0)==y0, w(0)==z0, Dx(0)==vx0, Dy(0)==vy0, Dz(0)==vz0];
sol = dsolve(eqn, cond);
u = sol.u ;
v = sol.v ;
w = sol.w ;
t = linspace(0,2*pi) ;
x = double(subs(u,t)) ;
y = double(subs(v,t)) ;
z = double(subs(w,t)) ;
display(sol);
plot3(x,y,z)
end

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by