Solve with several vectors
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Luciano Montanelli
el 19 de Ag. de 2022
Comentada: Luciano Montanelli
el 19 de Ag. de 2022
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 comentarios
Walter Roberson
el 19 de Ag. de 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.
Respuesta aceptada
Torsten
el 19 de Ag. de 2022
Editada: Torsten
el 19 de Ag. de 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
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Variables, Expressions, Functions, and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!