MATLAB: How to add Frenet frame vectors to plot

frenet framequiver3tnb

So far I have a plot for r(t) = [cos(t),sin(2*t), cos(2*t)] from 0 to 2*pi. I need to be able to plot the Frenet frame vectors at various points on the plot, say 5 different points. I've been given the following equations for the unit vectors t, n, and b:
where r = R(t) = [t*cos(t), t*sin(2*t),t] and r' and r'' are the first and second order time derivatives of R(t), respectively. Here is the code I have so far:
syms t
R = [t*cos(t), t*sin(2*t), t];
R_dot = diff(R,t)
R_ddot = diff(R_dot,t)
r = [cos(t), sin(2*t), cos(2*t)];
fplot3(r(1),r(2),r(3),[0,2*pi])
hold on
for t = 0:2*pi
th = R_dot/norm(R_dot)
bh = cross(R_dot,R_ddot)/norm(cross(R_dot,R_ddot));
bh = bh/norm(bh);
nh = cross(bh,th);
quiver3(cos(t),sin(2*t),cos(2*t),th(1),th(2),th(3),'r');
end
When I run the code, I get the error, 'Unable to convert expression into double array.' Any help is appreciated.

Best Answer

You cannot quiver() or quiver3() anything involving an unresolved symbolic variable.
What you are missing is that when you use
for t = 0:2*pi
and then use an expression that was defined in terms of the symbolic variable t, then those symbolic variables will not have the numeric value automatically substituted.
The situation is exactly like
A = 1
B = A + 1
A = 10
then afterwards B will still be 2, and will not become 11. The value of the variable is copied at the time the variable is used.
syms t
is the same as
t = sym('t');
so the value of the variable t at that point is a reference to the variable t that lives inside the symbolic engine. When you then later
t = 0; %numeric
then the t that lives inside the symbolic engine is not updated.
What you should do is more like,
syms t
R = [t*cos(t), t*sin(2*t), t];
R_dot = diff(R,t)
R_ddot = diff(R_dot,t)
r = [cos(t), sin(2*t), cos(2*t)];
fplot3(r(1),r(2),r(3),[0,2*pi])
hold on
th = R_dot/norm(R_dot)
%bh = cross(R_dot,R_ddot)/norm(cross(R_dot,R_ddot));
%bh = bh/norm(bh);
%nh = cross(bh,th);
T = linspace(0, 2*pi);
TH = subs(th, t, T.');
quiver3(cos(T), sin(2*T), cos(2*T), TH(:,1).', TH(:,2).', TH(:,3).', 'r');
I commented out bh and nh calculations because you are not using them.
Notice the correction to your t values. You had 0:2*pi, which would be 0:6.28-ish which is [0, 1, 2, 3, 4, 5, 6] -- only 7 values.