simscapeのローカルソルバーの設定を変更して連続実行
29 views (last 30 days)
Show older comments
Yoshitaka Hayakawa
on 23 Aug 2019
Commented: Yoshitaka Hayakawa
on 4 Sep 2019
どうすれば、matlabスクリプトファイルを使用して、simscapeのsolver configulationブロック内の設定を変更することができますか?
現在、matlabスクリプトで以下の関数を複数回実行するプログラムを作成しました。
silulink実行関数:sim('simulinkモデル名');
しかし、実行した際に以下のエラーが発生します.
['simulinkモデル名/Solver Configuration']: 初期条件の求解が収束しませんでした。
原因:
エラー: matlabスクリプトファイル名 (line 194)
時間を 1 ステップ進める非線形ソルバーが収束しませんでした。残差ノルムが大きすぎます。
このエラーの解決にはsimscapeのSolver Configurationブロック内の’整合性の許容誤差’を変えることで対処できることがわかっています。
しかし、エラーが発生するたびに手入力で修正するのは大変なので、スクリプト内にエラーに対処する関数などを加えたいです。
なにか方法をご存知でしたら、ご教授お願いいたします.
0 Comments
Accepted Answer
Toshinobu Shintai
on 25 Aug 2019
Solver Configulationのハンドルを取得すればスクリプトで変更することができるようになります。
例として以下のように整合性の許容誤差を変えながらシミュレーションするものを作ってみました。
%% 初期化
clear;
default_tolerance = 1e-9; % デフォルトの許容誤差
tol_factor = 10; % 許容誤差を増やす係数
rep_flag = true; % 繰り返しのフラグ
max_rep_count = 5; % 最大繰り返し回数
%% モデルを開く
open_system('mech_simple.slx');
%% Simulink内のSolver Configurationのハンドルを取得する
SC_Handle = getSimulinkBlockHandle('mech_simple/Solver_Configuration');
tor_text = num2str(default_tolerance);
% パラメータを上書きする
set_param(SC_Handle, 'ResidualTolerance', tor_text);
%% シミュレーション実行時のエラーが発生しなくなるまで繰り返し実行する
i = 0;
tor_temp = default_tolerance;
while(rep_flag)
try
sim('mech_simple.slx');
% 問題がなければここでループを終える
rep_flag = false;
catch
% パラメータを変更して上書きする
tor_temp = tor_temp * tol_factor;
tor_text = num2str(tor_temp);
set_param(SC_Handle, 'ResidualTolerance', tor_text);
% 最大反復回数を確認する
i = i + 1;
if (i >= max_rep_count)
break;
end
end
end
対象となるモデルは添付ファイルの「mech_simple.slx」です。R2019aで作成しました。
もしお持ちでない場合は「mech_simple.zip」を解凍してhtmlファイルでモデルを確認できます。
この方法で問題ありませんでしょうか。
More Answers (0)
See Also
Categories
Find more on トラブルシューティング in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!