vpasolve in for loop
2 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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
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)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!