Solve system of equations in simulink

5 次查看(过去 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]);

回答(1 个)

Ankita Nargundkar
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.

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by