Solve with several vectors

3 views (last 30 days)
Hi, I have these vectors:
int_v_d
int_i_d
i_d
int_omega_i_q
int_v_q
int_i_q
i_q
int_omega_i_d
theta
All of them have the same size and each of them is a column vector.
Now, I have a set of two equations like this one:
eq_1 = int_v_d == -R_AFPM * int_i_d - (i_d - i_d(1)) .* L_d + L_q .* int_omega_i_q;
eq_2 = int_v_q == -R_AFPM * int_i_q - (i_q - i_q(1)) .* L_q - L_d .* int_omega_i_d + ...
psi_f * theta;
The variables that are not vectors, and that I didn't mention before, are constants. I want to calculate the values L_d and L_q for each row.
I am using solve and subs functions for this, but I get this error:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function
first to substitute values for variables.
Error in sym/double (line 709)
Xstr = mupadmex('symobj::double', S.s, 0);
Here is my complete code:
syms int_v_d int_i_d i_d int_omega_i_q int_v_q int_i_q i_q int_omega_i_d theta L_d L_q
eq_1 = int_v_d == -R_AFPM * int_i_d - (i_d - i_d(1)) .* L_d + L_q .* int_omega_i_q;
eq_2 = int_v_q == -R_AFPM * int_i_q - (i_q - i_q(1)) .* L_q - L_d .* int_omega_i_d + ...
psi_f * theta;
sol = solve([eq_1;eq_2],[L_d;L_q]);
vec_L_d = double(subs(sol.L_d,{int_v_d;int_i_d;i_d;int_omega_i_q; ...
int_v_q;int_i_q;i_q;int_omega_i_d;theta},{int_v_d;int_i_d;i_d;int_omega_i_q; ...
int_v_q;int_i_q;i_q;int_omega_i_d;theta}));
vec_L_q = double(subs(sol.L_q,{int_v_d;int_i_d;i_d;int_omega_i_q; ...
int_v_q;int_i_q;i_q;int_omega_i_d;theta},{int_v_d;int_i_d;i_d;int_omega_i_q; ...
int_v_q;int_i_q;i_q;int_omega_i_d;theta}));
The result for L_d and L_q should be for each one a vector of the same size as the other vectors.
Thank you in advance.
  2 Comments
Walter Roberson
Walter Roberson on 19 Aug 2022
syms int_i_d
does not declare a vector. You need a size after it
eq_1 = int_v_d == -R_AFPM * int_i_d - (i_d - i_d(1)) .* L_d + L_q .* int_omega_i_q;
eq_2 = int_v_q == -R_AFPM * int_i_q - (i_q - i_q(1)) .* L_q - L_d .* int_omega_i_d + ...
psi_f * theta;
"The variables that are not vectors, and that I didn't mention before, are constants."
So L_q and L_d are constants, since you did not mention them before? Scalar constants?
"The result for L_d and L_q should be for each one a vector of the same size as the other vectors."
That would require that they are symbolic vectors since you are solving for them.
Luciano Montanelli
Luciano Montanelli on 19 Aug 2022
Edited: Luciano Montanelli on 19 Aug 2022
L_d and L_q should be vectors, since I should solve this set of equations with the vectors I specified at the beginning. R_AFPM and phi_f are the only constants (scalar constants).
I could solve this by calling every vector in syms with a different name, the same with every vector in the first {} in the subs arguments.
Thank you for your help, @Walter Roberson!

Sign in to comment.

Accepted Answer

Torsten
Torsten on 19 Aug 2022
Edited: Torsten on 19 Aug 2022
syms int_v_d_sym int_i_d_sym i_d_sym i_d1_sym int_omega_i_q_sym int_v_q_sym int_i_q_sym i_q_sym i_q1_sym int_omega_i_d_sym theta_sym L_d_sym L_q_sym R_AFPM_sym psi_f_sym
eq_1 = int_v_d_sym == -R_AFPM_sym * int_i_d_sym - (i_d_sym - i_d1_sym) .* L_d_sym + L_q_sym .* int_omega_i_q_sym;
eq_2 = int_v_q_sym == -R_AFPM_sym * int_i_q_sym - (i_q_sym - i_q1_sym) .* L_q_sym - L_d_sym .* int_omega_i_d_sym + ...
psi_f_sym * theta_sym;
sol = solve([eq_1;eq_2],[L_d_sym;L_q_sym]);
sol.L_d_sym
ans = 
sol.L_q_sym
ans = 
for i = 1:numel(int_v_d)
L_d(i) = double(subs(L_d_sym,[int_v_d_sym int_i_d_sym i_d_sym i_d1_sym int_omega_i_q_sym int_v_q_sym int_i_q_sym i_q_sym i_q1_sym int_omega_i_d_sym theta_sym R_AFPM_sym psi_f_sym],[int_v_d(i) int_i_d(i) i_d(i) i_d(1) int_omega_i_q(i) int_v_q(i) int_i_q(i) i_q(i) i_q(1) int_omega_i_d(i) theta(i) R_AFPM psi_f]))
L_q(i) = double(subs(L_q_sym,[int_v_d_sym int_i_d_sym i_d_sym i_d1_sym int_omega_i_q_sym int_v_q_sym int_i_q_sym i_q_sym i_q1_sym int_omega_i_d_sym theta_sym R_AFPM_sym psi_f_sym],[int_v_d(i) int_i_d(i) i_d(i) i_d(1) int_omega_i_q(i) int_v_q(i) int_i_q(i) i_q(i) i_q(1) int_omega_i_d(i) theta(i) R_AFPM psi_f]))
end

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!