Solve system of equations in simulink

조회 수: 4 (최근 30일)
Andrew Poissant
Andrew Poissant 2017년 6월 19일
답변: Ankita Nargundkar 2017년 6월 22일
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