필터 지우기
필터 지우기

Conversion to logical from symfun is not possible

조회 수: 6 (최근 30일)
Alex Muniz
Alex Muniz 2023년 1월 10일
답변: Walter Roberson 2023년 1월 10일
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

채택된 답변

Walter Roberson
Walter Roberson 2023년 1월 10일
There are two possibilities here:
  1. 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
  2. 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
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개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by