# Alternate code for magnitude or derivative?

6 views (last 30 days)
Spencer Rasmuson on 28 Sep 2021
Answered: Abhimenyu on 22 Apr 2024
I'm trying to calculate unit tangent, unit normal, and binormal vectors. If i'm understanding correctly the error comes when I try to divide rp by rn. What can I add to make this operation work, or how can I code this differently? Thank you all for your help.
syms t real;
%r = vector valued function
r = [2*cos(t),2*sin(t),4*t];
%r'
rp = diff(r,t);
%magnitude of r prime
rn = norm(rp);
%unit tangent vector
t = rp/rn;
%t'
tp = diff(t);
%magnitude of t'
tn = norm(tp);
% unit normal vector
n = tp/tn;
% binormal vector
b = cross(t,n);
%solve at pi/2
ans = subs(b,t,vt)
Error using sym/subs>normalize (line 235)
Inconsistency between sizes of second and third arguments.
[X2,Y2,symX,symY] = normalize(X,Y); %#ok
Error in sym/subs (line 154)

Abhimenyu on 22 Apr 2024
Hi Spencer,
From the information shared, I understand that you are trying to calculate unit tangent, unit normal, and binormal vectors. The error you are encountering seems to result from a mix-up with variable names and how the "subs" function is being used. Initially the variable "t" is a symbolic variable representing time or the parameter in the parametric equations. Later, it is redefined as the unit tangent vector, which is not only confusing but also overwrites the symbolic variable "t". This can lead to unexpected results or errors in symbolic computations. In the "subs" function, variable "vt" seems to be intended as a specific value at which "b" is to be calculated, but it's not defined.
syms t real;
% Vector valued function
r = [2*cos(t), 2*sin(t), 4*t];
% Derivative of r with respect to t
rp = diff(r, t);
% Magnitude of r prime
rn = norm(rp);
% Unit tangent vector
T = rp / rn; % Use a different variable name such as 'T' for the unit tangent vector
% Derivative of T with respect to t
Tp = diff(T, t);
% Magnitude of T prime
tn = norm(Tp);
% Unit normal vector
N = Tp / tn; % Use 'N' for the unit normal vector
% Binormal vector
B = cross(T, N);
% Solve at t = pi/2
% Specify the value at which you want to evaluate 'B'
specific_t_value = pi/2;
evaluated_B = subs(B, t, specific_t_value)
evaluated_B =
The above mentioned code involves changing the variable name for the unit tangent vector from "t" to "T" to avoid conflict with the symbolic variable "t". Similarly, it uses "N" for the unit normal vector and "B" for the binormal vector to maintain clarity. It also correctly substitutes "t" with a specific value, "pi/2", in the final step.
I hope this helps!