Solve with several vectors

3 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2022-8-19
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 2022-8-19
编辑:Luciano Montanelli 2022-8-19
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!

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2022-8-19
编辑:Torsten 2022-8-19
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Variables, Expressions, Functions, and Settings 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by