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
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.
采纳的回答
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
sol.L_q_sym
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 Center 和 File Exchange 中查找有关 Symbolic Variables, Expressions, Functions, and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!