- eqn1, eqn2, eqn3 do not involve any unresolved symbolic variables before the loop, so you can double() them before the loops start and pre-calculate eqn1 && eqn2 && eqn3 -- the condition would either be true for all loop iterations or for none at all; or
- at least one of eqn1, eqn2, eqn3 involve any unresolved symbolic variables, In this case, eqn1 && eqn2 && eqn3 cannot be resolved, and looping changing ki and kd is not going to change that
Conversion to logical from symfun is not possible
4 次查看(过去 30 天)
显示 更早的评论
How to fix this error: Conversion to logical from symfun is not possible ?
Code:
syms s eqn1 eqn2 eqn3;
kp = sym('kp','real');
ki = sym('ki','real');
kd = sym('kd','real');
w = sym('w','real');
i0 = 1;
i1 = 1;
i2 = 1;
eqn1 = (subs(V_jw_even,w,0))*i0 > 0;
eqn2 = (subs(V_jw_even,w,w_roots))*i1 > 0;
eqn3 = (subs(V_jw_even,w,inf))*i2 > 0;
% [ V_jw_even] is a symbolic polynomial. V_jw_even = (- kd - 1)*w^4 + (ki - 9*kd + 17)*w^2 + 9*ki
% [w_roots] is a real and positive root . w_roots ~= 1.4638
% Define o passo de busca para x e y
step = 0.5;
solution_found = false;
% Enquanto a solução ainda não foi encontrada
for ki = x_min:step:x_max
for kd = y_min:step:y_max
% Verifica se as inequações são satisfeitas para os valores atuais de x e y
solution_found = eqn1 && eqn2 && eqn3;
if solution_found
fprintf('Solucao encontrada: x = %.2f, y = %.2f\n', ki, kd);
solution_found = true;
end
end
end
0 个评论
采纳的回答
Walter Roberson
2023-1-10
There are two possibilities here:
The second situation would be different if you were to subs() to evaluate the conditions.
I want you to consider for a moment the code segment
a = 2
b = a^2 + 1
a = 7
What is the value of b after that code? Does b get automatically recalculated accounting for the new version of a and so become 7^2+1, keeping some kind of internal history of how it was calculated and getting recalculated when the variables involved changed? If so then how would you possibly be able to handle b = b + 1 ? Or... does the current value of a get used to calculate b and then b promptly forgets how it was calculated, so that when a changes, b does not change?
The situation is the same with
syms a
b = a^2 + 1
a = 7
At the time the b = a^2 + 1 is calculated, a is a reference to a symbolic variable and b gets assigned a symbolic result. When you then a=7 then b still uses that reference to a as a symbolic variable and does not get recalculated with the change in a
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!