How to write Code in Matlab function block in simulink?
2 ビュー (過去 30 日間)
古いコメントを表示
Dear all,
I want to solve four equation in matlab function block in simulink.
four equation are
- T=(Mf*id);
- d(ws)/dt=(10000-T+D(314.15-ws));
- Q=(ws*Mf*iq);
- d(Mf)/dt=(3000-Q+K(325-V));
Equation are interlink, so, there form a loops. e.g to sole Qs(k) need Mf(k) and to solve Mf(k) need Q(k). And same with T(k) and ws(k), interlink with Mf(k).
So, my question is how to write Code in Matlab function block in simulink to solve this loops?
2 件のコメント
Alan Bindemann
2020 年 8 月 8 日
I don't think you can solve it entirely in a MATLAB Function block. You could solve it with a MATLAB function block that returns the right-hand sides of equations 1-4. You could then pass the derivative terms (2 and 4) into separate integrator blocks that return ws and Mf back into the MATLAB function block. The initial values of ws and Mf would be set in the integrator blocks as initial conditions.
function [T, dwsDt, Q, dMfDt] = foo(Mf, id, T, D, ws, iq, Q, K, V)
%#codegen
T = Mf*id;
dwsDt = (10000 - T + D*(314.15-ws));
Q = ws*Mf*iq;
dMfDt = 3000 - Q + K*(325 - V);
end
回答 (1 件)
Aman Vyas
2020 年 8 月 11 日
Hi Ajinkya,
From the equations it is clear that all of them are interlinked.
You can get started by :
a) Taking two integral blocks, with d(ws)/dt and d(Mf)/dt as input, you will get ws and Mf as output.
b) Since now you have all the variables available, you can directly pass it to the function block with putting in equations in above fashion.
So considering 2 integral blocks with one matlab function will make your task easier overall.
Hope it helps !
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Simulink Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!