how to do vector symbolic differentiation

could I get help in writing vector symbolic differentiation
I wanna declare LA , Th2_2 ,ThA_2 as vectors where their values are seted in vector (1,11) for differtent time . note that each value of LA, Th2_2 and ThA_2 correspond to each other for the same time. so they must be used in the equation based on that.
how can I edit the code to get the solutions for Om2 and OmA as vectors as well
Thanks in advance for any help..
%Parameters
syms L1_2 L2_2 Th1 Th1_2 integer
% variables and their derivatives
syms LA Th2_2 Om2 ThA_2 OmA integer
%loop eqn.
L_eqn1 = L2_2*exp(1i*Th2_2)+LA.*exp(1i*ThA_2) -L1_2*exp(1i*Th1_2)==0;
%velocity eqn for Om2 and OmA.
dL_eqn1 = diff(L_eqn1,Th2_2)*Om2 +diff(L_eqn1,ThA_2)*OmA- v*exp(1i*ThA_2);
real_vel_eqn1 = real(dL_eqn1);
imag_vel_eqn1 = imag(dL_eqn1);
[Om2, OmA]=solve (real_vel_eqn1, imag_vel_eqn1);

6 Comments

LA = sym('LA', [1 11], 'integer');
Like that ?
I think so.. I did this for Th2 Om2 and OmA as well but I got anoter errors saying:
" Error using symengine
Dimensions do not match.
Error in sym/privBinaryOp (line 1022)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in * (line 317)
X = privBinaryOp(A, B, 'symobj::mtimes');
Error in th2try (line 86)
dL_eqn1 = diff(L_eqn1)*Om2 +diff(L_eqn3)*OmA- v*exp(1i*ThA_2);"
Could you post your updated code?
The derivative of something calculated from scalars multiples of integer variables is going to be discontinuous, existing only as dirac delta functions at best.
I dont want variables to be integar so I changed to real
%Parameters
syms L1 L2 L3 L4 L1_2 L2_2 Th1 Th1_2 real
% variables and their derivatives
LA = sym('LA', [1 11], 'real');
ThA_2 = sym('ThA_2', [1 11], 'real');
Th2_2 = sym('Th2_2', [1 11], 'real');
Om2 = sym('Om2', [1 11], 'real');
OmA = sym('OmA', [1 11], 'real');
%loop eqn.
L_eqn1 = L2_2*exp(1i*Th2_2)+ LA.*exp(1i*ThA_2) -L1_2*exp(1i*Th1_2)==0;
%velocity eqn for Om2 and OmA.
dL_eqn1 = diff(L_eqn1,Th2_2)*Om2 +diff(L_eqn1,ThA_2)*OmA- v*exp(1i*ThA_2)==0;
real_vel_eqn1 = real(dL_eqn1)==0;
imag_vel_eqn1 = imag(dL_eqn1)==0;
[Om2, OmA]=solve (real_vel_eqn1, imag_vel_eqn1);
diff(L_eqn1,Th2_2)
You are asking to differentiate the vector L_eqn1 at the vector of variables Th2_2 . With the vectors being the same length, perhaps you are wanting to differentiate with corresponding variables. A single diff() call will not do that, but you can
arrayfun(@diff, L_eqn1, Th2_2)
Keep in mind, though, that you are differentiating an equation, which is going to have the effect of differentiating both sides of the equation. It is legal to then multiply by a constant, which has the effect of multiplying both sides by a constant, and it is legal to add equations... but when you find yourself multiplying or adding equations, you should stop to ask yourself whether that is really what you want to do, or if instead you should be working with just the expressions rather than the equations.

Sign in to comment.

Answers (0)

Asked:

on 3 Nov 2019

Commented:

on 3 Nov 2019

Community Treasure Hunt

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

Start Hunting!