this is my first question here.
I am having trouble, I might be able to express what I want in Matlab but I suffer to do that in Mathematica.
So I have a direction cosine matrix that is solved in NDsolve. I have a vector, say vec(0)={1,0,0}. I want to have these initial conditions and do a time marching to this vector (i.e. multiply it with my direction cosine matrix which is also time-dependent, and as mentioned solved in NDsolve). In the end, I want to create an animation of that vector.
I tried to put x’ (first component of vector), y’, and z’ expression in the NDsolve where I get the components of direction cosine (please do not confuse it with built-in direction cosine it has nothing to do with my assignment); but it turned out that putting x’, y’, z’ somehow managed to mess up my solution.
I am open to brand new approach to obtain this vector.
I add last part of my code below.
tmax = 10
m = 4
lx = 0.3
ly = 0.1
lz = 0.1
eqnplotorig = {Derivative(1)((Theta)x)(t) ==
Sec((Theta)y(t)) (Cos((Theta)z(t)) (Omega)x(t) -
Sin((Theta)z(t)) (Omega)y(t)),
Derivative(1)((Theta)y)(t) ==
Sin((Theta)z(t)) (Omega)x(t) + Cos((Theta)z(t)) (Omega)y(t),
Derivative(1)((Theta)z)(
t) == -Cos((Theta)z(t)) Tan((Theta)y(t)) (Omega)x(t) +
Sin((Theta)z(t)) Tan((Theta)y(t)) (Omega)y(t) + (Omega)z(t),
Derivative(1)((Omega)x)(
t) == (36 lx^2 ly lz (ly^2 - lz^2) (Omega)x(t)^2 -
3 lx (Omega)x(
t) ((9 ly^4 lz + 22 ly^2 lz^3 - 3 lz^5 -
lx^2 (11 ly^2 lz + 3 lz^3)) (Omega)y(t) +
ly (3 ly^4 - 22 ly^2 lz^2 - 9 lz^4 +
lx^2 (3 ly^2 + 11 lz^2)) (Omega)z(t)) -
4 (-3 ly (lx^2 - 2 ly^2) lz (lx^2 + lz^2) (Omega)y(t)^2 +
2 (lx^2 + ly^2) (ly^2 - lz^2) (lx^2 + lz^2) (Omega)y(
t) (Omega)z(t) +
3 ly (lx^2 + ly^2) lz (lx^2 - 2 lz^2) (Omega)z(
t)^2))/(5 lx^4 (ly^2 + lz^2) + 32 ly^2 lz^2 (ly^2 + lz^2) +
lx^2 (5 ly^4 - 62 ly^2 lz^2 + 5 lz^4)),
Derivative(1)((Omega)y)(
t) == (3 lx (5 lx^2 - 16 ly^2) lz (ly^2 + lz^2) (Omega)x(
t)^2 + (Omega)x(
t) (3 ly lz (lx^2 (-23 ly^2 + lz^2) +
12 (ly^2 + lz^2)^2) (Omega)y(
t) + (lx^2 + ly^2) (5 lx^2 + 12 ly^2 - 20 lz^2) (ly^2 +
lz^2) (Omega)z(t)) +
3 lx (3 ly^2 lz (-4 lx^2 + 3 ly^2 + 7 lz^2) (Omega)y(t)^2 +
ly (3 ly^4 + 20 ly^2 lz^2 + 9 lz^4 +
lx^2 (3 ly^2 - 13 lz^2)) (Omega)y(t) (Omega)z(
t) + (lx^2 + ly^2) lz (7 ly^2 - 5 lz^2) (Omega)z(
t)^2))/(5 lx^4 (ly^2 + lz^2) + 32 ly^2 lz^2 (ly^2 + lz^2) +
lx^2 (5 ly^4 - 62 ly^2 lz^2 + 5 lz^4)),
Derivative(1)((Omega)z)(
t) == (-3 lx ly (5 lx^2 - 16 lz^2) (ly^2 + lz^2) (Omega)x(
t)^2 - (Omega)x(
t) ((lx^2 + lz^2) (ly^2 + lz^2) (5 lx^2 - 20 ly^2 +
12 lz^2) (Omega)y(t) +
3 ly lz (lx^2 (ly^2 - 23 lz^2) +
12 (ly^2 + lz^2)^2) (Omega)z(t)) +
3 lx ((lx^2 + lz^2) (5 ly^3 - 7 ly lz^2) (Omega)y(t)^2 -
lz (9 ly^4 + 20 ly^2 lz^2 + 3 lz^4 +
lx^2 (-13 ly^2 + 3 lz^2)) (Omega)y(t) (Omega)z(t) -
3 ly lz^2 (-4 lx^2 + 7 ly^2 + 3 lz^2) (Omega)z(
t)^2))/(5 lx^4 (ly^2 + lz^2) + 32 ly^2 lz^2 (ly^2 + lz^2) +
lx^2 (5 ly^4 - 62 ly^2 lz^2 + 5 lz^4)), (Theta)x(0) ==
0, (Theta)y(0) == 0, (Theta)z(0) == 0, (Omega)x(0) ==
2 (Pi)/180, (Omega)y(0) == 2 (Pi)/180, (Omega)z(0) ==
2 (Pi)/180}
solplot3Dorig =
Flatten@NDSolve(
eqnplotorig, {(Theta)x, (Theta)y, (Theta)z, (Omega)x,
(Omega)y, (Omega)z}, {t, 0, tmax})
Plot(Evaluate({(Theta)x(t), (Theta)y(t), (Theta)z(t)} /.
solplot3Dorig), {t, 0, tmax},
PlotLegends ->
Placed({(Theta)x(t), (Theta)y(t), (Theta)z(t)}, {0.85, 0.55}))
Plot(Evaluate({(Omega)x(t), (Omega)y(t), (Omega)z(t)} /.
solplot3Dorig), {t, 0, tmax},
PlotLegends ->
Placed({(Omega)x(t), (Omega)y(t), (Omega)z(t)}, {0.85, 0.55}))
Here I solve theta values that will be used in my direction cosine matrix. Which is defined as :
Dirmat = {{1, 0, 0}, {0, Cos((Theta)x(t)), -Sin((Theta)x(t))}, {0,
Sin((Theta)x(t)), Cos((Theta)x(t))}} . {{Cos((Theta)y(t)), 0,
Sin((Theta)y(t))}, {0, 1, 0}, {-Sin((Theta)y(t)), 0,
Cos((Theta)y(t))}} . {{Cos((Theta)z(t)), -Sin((Theta)z(t)),
0}, {Sin((Theta)z(t)), Cos((Theta)z(t)), 0}, {0, 0, 1}}
So what I need is a “vec” vector variable time march that has some initial values like {1,0,0} (or whatever) and time march it so that I can animate it using “frames” or something like that.
Sorry, it was a long question.
Any help will be appreciated.