MATLAB Compiler で 'syms' と 'solve' を含む MATLAB 関数をデプロイすることはできますか?
6 views (last 30 days)
Show older comments
MathWorks Support Team
on 24 Jan 2024
Edited: MathWorks Support Team
on 29 Feb 2024
Symbolic Math Toolbox の 'syms' と 'solve' を含む以下のようなコードをコンパイルしようとするとこれらの関数が除外されたという旨の警告が表示されました。対策を教えてください。
function sample(a, b, c)
syms x
eqn = a*x^2 + b*x + c == 0;
s = solve(eqn);
y = vpa(s);
disp(y)
end
警告: MATLAB Compiler ライセンスに従って、"C:\Users\XXXXX\Documents\MATLAB\Projects\Learning\YYYYYY.m" 内の "syms" は MATLAB ランタイム環境のパッケージから除外されます。このファイルまたは関数をコードから削除するか、MATLAB 関数 "isdeployed" を使用して、関数がデプロイ コンポーネントから呼び出されないようにしてください。
Accepted Answer
MathWorks Support Team
on 29 Feb 2024
Edited: MathWorks Support Team
on 29 Feb 2024
'syms' と 'solve' を含む、入力引数を持つ MATLAB 関数をコンパイルする手順は以下の通りです。
1.以下の修正コードから無名関数を生成し、入力引数 a、b、c を設定します。
syms a b c x
eqn = a*x^2 + b*x + c == 0;
s = solve(eqn)
f = matlabFunction(s)
無名関数は以下のように確認できます。
f =
function_handle with value:
@(a,b,c)[((b+sqrt(a.*c.*-4.0+b.^2)).*(-1.0./2.0))./a;((b-sqrt(a.*c.*-4.0+b.^2)).*(-1.0./2.0))./a]
2. 'syms' や 'solve' を使用する代わりに無名関数を使用します。
function sample(a, b, c)
f = @(a,b,c)[((b+sqrt(a.*c.*-4.0+b.^2)).*(-1.0./2.0))./a;((b-sqrt(a.*c.*-4.0+b.^2)).*(-1.0./2.0))./a];
y = f(a,b,c);
disp(y)
end
3. 以下のようにコンパイルと生成されたスタンドアロンアプリケーションを実行できます。
>> mcc -m sample.m
>> ! sample 1 2 3
-0.5102 - 0.8835i
-0.5102 + 0.8835i
0 Comments
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!