Solve system of equations in simulink
3 ビュー (過去 30 日間)
古いコメントを表示
I wrote a script to solve a system of 3 equations in matlab. The code can be seen below. I need to add this in simulink simulink's matlab function block does not support symbolic variables. I would just leave everything in matlab but there is already a simulation in Simulink that I need to add this matlab function block to. Does anyone have any suggestions on how I can execute this matlab script in simulink?
syms u dt u_z
hf = 0;
u0 = 16;
Alt = 69.96;
dz = hf - Alt;
a = 2;
theta = 35;
phi = 10;
ax = a*cosd(theta)*cosd(phi);
ay = a*sind(theta)*cosd(phi);
az = a*sind(phi) - 9.8;
f1 = 0 == u0 + a*dt - u;
f2 = 0 == u*sind(phi) - u_z;
f3 = 0 == (u_z - sqrt(2*az*dz + u_z^2)/az) - dt;
[u, u_z, dt] = solve([f1, f2, f3], [u, u_z, dt]);
0 件のコメント
回答 (1 件)
Ankita Nargundkar
2017 年 6 月 22 日
Use 'matlabFunction' to create a numerical equivalent of the symbolic expressions. Refer to this link
For example:
matlabFunction(u, u_z, dt,'file','sysEqn')
Will create 'sysEqn.m' that gives the numerical values of u, u_z, dt. You can parameterize the resulting function by making sure any parameters are defined as 'syms' in the original symbolic code.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!