필터 지우기
필터 지우기

Whenever i try so solve for 's' i get the same error:

조회 수: 2 (최근 30일)
Germán Portellano Rodríguez
Germán Portellano Rodríguez 2023년 11월 2일
댓글: Walter Roberson 2023년 11월 2일
syms s
G= 1/((s+2)*(s+1)*(s+3)*(s+7)^2)
G = 
K= -1/G;
dk=diff(K)
dk = 
sol=eval(solve(dk==0,'Real',true))
Error using evalin
Unrecognized function or variable 'z'.

Error in sym/eval (line 13)
s = evalin('caller',vectorize(char(x)));
eval(subs(K,s,sol))
Error using evalin
Unrecognized function or variable 'z'.
Error in sym/eval (line 13)
s = evalin('caller',vectorize(char(x)));
Error in PEC2122 (line 8)
sol=eval(solve(dk==0,'Real',true))

답변 (2개)

Walter Roberson
Walter Roberson 2023년 11월 2일
Never eval() a symbolic expression or symfun or symbolic matrix expression. There is no documented meaning for eval() of any of those. In practice, eval() of any of them is eval() of char() of them . Which is a problem because char() of a symbolic expression does not always result in MATLAB code.
syms s
G = 1/((s+2)*(s+1)*(s+3)*(s+7)^2)
G = 
K = -1/G;
dk = diff(K)
dk = 
sol = vpa(solve(dk==0,'Real',true))
sol = 
vpa(subs(K,s,sol))
ans = 
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 11월 2일
By the way, you can get exact solutions for this system:
syms s
G = 1/((s+2)*(s+1)*(s+3)*(s+7)^2)
G = 
K = -1/G;
dk = diff(K)
dk = 
sol = solve(dk==0,'Real',true, 'maxdegree', 3)
sol = 
simplify(sol)
ans = 

댓글을 달려면 로그인하십시오.


Dyuman Joshi
Dyuman Joshi 2023년 11월 2일
Avoid the use eval as much as possible. And it is not required here.
If you want to convert the symbolic numbers to numeric data format, use double.
syms s
G = 1/((s+2)*(s+1)*(s+3)*(s+7)^2);
K = -1/G;
dk = diff(K);
sol = solve(dk==0, 'Real', true)
sol = 
sol = vpa(sol)
sol = 
subs(K,s,sol)
ans = 

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by