Writing equation in Simscape
14 次查看(过去 30 天)
显示 更早的评论
Hello All,
I got got while implementing a piece of code in Simscape. Any help would be highly appreciated.
I need to solve following equations: q(phi) = k2*phi - 0.5*(k1 - k2)(phi - delta - phi - delta) W(phi) = dq/d(phi) = k1 if phi < delta k2 if phi > delta
I have tried writing the following piece of code. It builds but when compiling from the Simulink it says the number of differential equation more than the number of variables.
component memristorLC < foundation.electrical.branch
parameters
k1 = {-3e4, 'Ohm^-1'};
k2 = {9e4, 'Ohm^-1'};
phi_0 = {0, 'V*s'};
delta = {1e-12, 'V*s'};
phi = {1e-14, 'V*s'};
end
variables
q = {3, 'A*s'};
w = {0.4, 'Ohm^-1'};
end
function setup
phi = phi_0;
if (phi_0 > delta || phi_0 < -delta)
error('Initial value of phi must be within the range of [-delta, delta]');
end
end
equations
q == k2*phi + 0.5*(k1 - k2) * (abs(phi + delta) - abs(phi - delta));
%
% if (abs(phi) < delta)
% q.der == k1*{1, 'V'};
% else
% q.der == k2*{1, 'V'};
% end
if (abs(phi) < delta)
w == k1;
else
w == k2;
end
w == q.der/{1,'V'};
i == w*v;
end
end
0 个评论
采纳的回答
Sebastian Castro
2015-5-22
Well, you have 4 total variables: V and i inherited from the branch, and your additional custom variables q and w.
By inheriting from the electrical branch, you have also inherited 1 equation defining the sign convention of V ... it's something like V == P.v - N.v; .
That leaves you with 3 equations to properly define the system, but you seem to have 4 in your component (Assuming that you plan on leaving that one part commented out).
Without knowing much about your model, it seems like both phi and its initial value phi_0 are in the parameters section. It therefore seems like this could be a dynamical state. If you move phi to the variables section, that should round off your number of variables vs. number of equations.
Also, if you are using R2014a or later, all variables will show up in the "Variables" tab of your block, so you could specify the initial phi value directly there without the need to make it an explicit parameter in the .ssc file.
- Sebastian
4 个评论
Sebastian Castro
2015-5-22
Yes, I think that should be the same.
Simscape doesn't like when multiple equations try to affect the same variable (in your case, q or q.der)... So, making k1 and k2 affect w instead is a way to get around these limitations, since there is another equation that relates w to q anyhow.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulation Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!