Writing equation in Simscape

조회 수: 14 (최근 30일)
Shital
Shital 2015년 5월 22일
댓글: Shital 2015년 5월 24일
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

채택된 답변

Sebastian Castro
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
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.
Shital
Shital 2015년 5월 24일
Hi,
Still I am not able to get what I am supposed to get. Here "phi" value is never going to negative values, which it should go.
Let me elaborate it a little bit: It is from electrical foundation. So,
q(phi) = k2*phi - 0.5*(k1 - k2)(|phi - delta| - phi - delta) ---(1)
W(phi) = dq/d(phi) = k1 if phi < delta and k2 if phi > delta ---(2)
i = v*w ------(3)
Since this is a memristor design, it satisfy basic equs:
i = dq/dt
and
v = d(phi)/dt
I have no clue what I am doing mistake in coding. Any suggestions will be highly appreciated.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulation Setup에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by