vpasolve in for loop

조회 수: 5 (최근 30일)
maedeh Gh
maedeh Gh 2019년 2월 19일
댓글: Etsuo Maeda 2019년 3월 5일
I Run this code and it works correctly, but I wanna stop the for loop when it gets Empty sym: 0-by-1
for p=0:10
ub= vpasolve(function==0,x,[1000*p,1000*(p+1)])
end

답변 (1개)

Etsuo Maeda
Etsuo Maeda 2019년 3월 5일
"vpasolve" returns numerical values. Its output "ub" cannot be a sym variable. If you use "solve", you can use "isempty" and "break" for your pourpose.
syms x
for k = 1:2
out = solve(x^k + 1 == 0, x)
if isempty(out) == 1
disp('break')
break;
end
disp('in loop')
end
HTH
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 3월 5일
This is not quite correct. vpasolve() returns symbolic values that represent numeric values. They are sym, and when no solution is found then the empty sym can be returned.
Also there is no need to compare isempty() to 1: you can just test if isempty(out)
Etsuo Maeda
Etsuo Maeda 2019년 3월 5일
UUUps, thank you very much for your kind correction :-)

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

카테고리

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