Writing equation in Simscape

14 Ansichten (letzte 30 Tage)
Shital
Shital am 22 Mai 2015
Kommentiert: Shital am 24 Mai 2015
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

Akzeptierte Antwort

Sebastian Castro
Sebastian Castro am 22 Mai 2015
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 Kommentare
Sebastian Castro
Sebastian Castro am 22 Mai 2015
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 am 24 Mai 2015
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulation Setup finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by