필터 지우기
필터 지우기

How to compute the gradient at each point of an arbitrary symbolic curve defined by "n" points?

조회 수: 5 (최근 30일)
Hello,
I have a vector of "n" points describing a spline. I would like to compute the gradient at each of the "n" points.
Each point in this vector has 3 components, each of which is a symbolic expression in multiple variables.
The reason I am computing the gradients is to compare 2 curves (one of which I know each point in a 3-D space) with this. My criterion for comparison is that the cross product of gradients at each point must be zero. I am able to compute the gradients of the known curve using the matlab function "gradient". However, when i use the same function to compute for the symbolic points, I get the error
**************************************
Error using sym/gradient (line 21)
First argument must be scalar.
***************************************
Any help on how I may proceed is apprecciated.
For ref:
known_points=[3Xn] % format double
dx_1=gradient(known_points(1,1:end));
dy_1=gradient(known_points(2,1:end));
dz_1=gradient(known_points(3,1:end));
% I am able to compute the above expressions.
unknown_points=[3Xn] %format sym
dx_2=gradient(unknown_points(1,1:end));
dy_2=gradient(unknown_points(2,1:end));
dz_2=gradient(unknown_points(3,1:end));
% I get the highlighted error when i compute the above expressions.
% alternately i have also tried dx_2=gradient(unknown_points(1,1:end), symvar(unknown_points)); to no avial.

채택된 답변

VBBV
VBBV 2022년 2월 13일
편집: VBBV 2022년 2월 13일
gradient(subs(unknown_points,x,value));
If x is the symbolic variables in array unknown_points then use subs to replace the variable with your value. Then compute the gradient as above.
  댓글 수: 2
Suhas Raghavendra Kulkarni
Suhas Raghavendra Kulkarni 2022년 2월 13일
Thank you for your answer. If I understand correctly, you are asking me to replce the desired values in place of the variable.
Unfortunately this is not possible as the symbolic function is actually a very long non-linear function in multiple variables. So I do not have the desired value of all the variable to replace in the expression.
Please correct me if my understanding of your answer is wrong.
VBBV
VBBV 2022년 2월 13일
Ok. In that case use diff without subs function instead of gradient with subs

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by