Alternate code for magnitude or derivative?

2 次查看(过去 30 天)
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.
Error in sym/subs>mupadsubs (line 166)
[X2,Y2,symX,symY] = normalize(X,Y); %#ok
Error in sym/subs (line 154)
G = mupadsubs(F,X,Y);

回答(1 个)

Abhimenyu
Abhimenyu 2024-4-22
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.
Please follow the example MATLAB code below that addresses and resolves the above-mentioned issues:
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!

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by