Shortening a transfer function in matlab? - matlab

How could I prune or shorten a transfer function in Matlab?
For example I could shorten s, (s-20) and (s+300.8). But how in Matlab?
533.4 s (s+300.8) (s-20) (s+3.948)
----------------------------------
s (s+20) (s-20) (s+300.8)

Ok, I found it!
minreal() is the answer.

If you have Symbolic Math Toolbox, you can use simplify:
syms s;
simplify((533.4 * s * (s + 300.8) * (s - 20) * (s + 3.948)) / (s * (s + 20) * (s - 20) * (s + 300.8)))
ans =
(2667*(s + 987/250))/(5*(s + 20))

Related

I can not prove that ((m xor a) xor (m and a))= (m or a)

I can not prove that ((m xor a) xor (m and a))= (m or a)
The truth table shows that they are, but I can't prove it using boolean algebra.
Can you guys help?
Thanks
OR: m+a
AND: m*a
XOR: [NOT(m) * a] + [m * NOT(a)]
[(m OR a) XOR (m AND a)] = [(m+a) XOR ( m*a)]=
= [NOT(m+a) * m * a] + [(m+a) * NOT(m*a)]=
= [NOT(m) * NOT(a) * m * a] + [(m+a) * (NOT(m) + NOT(a))]=
= [NOT(m) * NOT(a) * a * m] + a * NOT(a) + a * NOT(m) + m * NOT(a) + m * NOT(m) =
= 0 + 0 + a * NOT(m) + m * NOT(a) + 0 =
= a * NOT(m) + m * NOT(a) = m XOR a

Simplifying following Boolean Expression and verify using Karnaugh Map

I'm having trouble simplifying these two boolean expressions algebraically and proving them with a Karnaugh Map. How can I do this?
These are my two expressions:
1) (X * Y) + (X' * Y * Z')+ (Y * Z)
2) (X * Y') + Z + (X' + Y)+ (Y * Z)
I've tried going through it using the boolean theorems and laws to reduce them but I always come up with different answers. My answers usually comes up as this.
1) (Y * Z') + (X' * Y)
2) (X' * Y') + (X * Y' * Z')
I don't know if my K-Map is wrong, but I do need someone to help me understand how to solve this problem and the steps or laws I need to get the answer, so that I can master it. It is practice for exam, and I suck at boolean algebra. I appreciate it.
Let's start with the first expression:
E = XY + X'YZ' + YZ
The three terms have Y, then we can factor it out
E = Y(X + X'Z' + Z)
Now let's concentrate in the expression in parenthesis S = X + X'Z' + Z:
S = X + X'Z' + Z
= X + (X + Z)' + Z (De Morgan)
= (X + Z) + (X + Z)' (regrouping)
so, despite the fact that this still looks complex it has the form
S = p + p'
for p = X + Z, right? But p + p' = 1 (or true) no matter the value of p. Thus the expression S is 1 and we get
E = Y(X + X'Z' + Z) = YS = Y1 = Y
In other words, the first expression reduces to Y.
Notice also that it is not that hard to see why S = 1 without rewriting it. There are three cases: (a) If X is true, then certainly the expression is true. (b) If Z is true, the result is true also. (c) If none of X and Z are true then both are false and X'Z' is true. So, in each of these 3 cases at least one of the terms is true, hence their sum.
Let's now consider the second expression
F = XY' + Z + (X' + Y) + YZ
The first thing to note is that XY' is the opposite of (X' + Y):
(X' + Y) = (XY')' (De Morgan)
So,
F = XY' + (XY')' + Z + YZ
Again, regardless of the fact that XY' + (XY')' looks complicated, it is an expression of the form p + p'. But p + p' = 1 (it is always true) and therefore
F = 1 + Z + YZ = 1
no matter the values of Y and Z. So, the second expression is nothing but 1 (aka true).

How to create, solve and plot conditional function in matlab

For example,
I have a
f(x)=
9+4(x+3), if -4<=x<-1 (subf1)
7-9(x-0.4), if -1<=x<1 (subf2)
How can I create a function of f(x) in matlab?
I tried
f=0
syms x
f=f+ subf1 with heaviside+ subf2 with heaviside
But I cannot give a v to solve f(v) and I cannot plot f(x) only from -4 to 1.
So is there another way to write conditional function?
Sorry my description is a little hard to follow. If you don't understand what I am asking, please let me know and I will try to rephrase. Thank you!
Depends on what you want to do with it. If for some reason you need symbolic, here is one way to write your symbolic function:
syms x
f1 = (9 + 4 * (x + 3)) * heaviside(x + 4) * (1 - heaviside(x + 1));
f2 = (7 - 9 * (x - 0.4)) * heaviside(x + 1) * (1 - heaviside(x - 1));
f = symfun(f1 + f2, x);
Otherwise, you can write your function in a file as:
function out = f(x)
out = (9 + 4 * (x + 3))*(x>=-4)*(x<-1) + (7 - 9 * (x - 0.4))*(x>=-1)*(x<1);
Or you can define it as an anonymous function:
f = #(x) (9 + 4 * (x + 3))*(x>=-4)*(x<-1) + (7 - 9 * (x - 0.4))*(x>=-1)*(x<1);
Then, you can plot any of the functions using, for instance, fplot:
fplot(f, [-4, 1])

Can someone explain the simplification of this boolean algebra equation?

I think I missed reading a theorem or postulate or something..
The equation is: wy + wxz + xyz
According to my professor, the simplification is (which she didn't explain how):
wy + xz(w'y + wy')
= wy + xz (w XOR y)
Where did that (w'y + wy') came from??
I tried to calculate it but so far I only got: (w+x)(w+y)(w+z)(x+y)(y+z)
In a Boolean expression + is XOR and * is AND. This is the same as identifying true with 1 and false with 0, with the only special convention that 1 + 1 = 0 (or 2 = 0 if you wish.)
With these definitions both + and * are commutative, i.e., a + b = b + a and a * b = b * a. In addition, the distributive law is also valid a * (b + c) = a * b + a * c. Note also that the * operator is usually implicit in the sense that we write ab instead of a * b.
Applying these properties to the expression wy + wxz + xyz, there are some few obvious transformations you can do:
wy + wxz + yxz (commute x with y)
wy + (w + y)xz (prev plus distribute xz)
wy + xz(w + y) (prev plus commute (w + y) with xz
Note that the last one is wy + xz(w XOR y) because + is nothing but XOR.
ADDENDUM
Regarding the expression of your professor, let's recall that a' = 1 - a by definition. So
w'y + wy' = (1 - w)y + w(1 - y) - def
= y - wy + w - wy - distribute
= y + w - simplify (a + a = 0 always)
= w + y - commute
which shows that s/he was right.

MATLAB: Why does solve return an empty sym object?

I´m trying to solve this set of equations in MATLAB and I get an empty sym object:
equations = {'I2B+I2EQAB=I22B+I2EQBC',...
'I2A=I2EQAB+I2EQAC+I22A',...
'I2C+I2EQBC+I2EQAC=I22C',...
'I22B=IZB+IC1B',...
'IZB=IC2B+IZBB',...
'I22C=-I2C*Z2C*YC/2+IZC',...
'IZC=IC2C+IZCC',...
'I22A=IC1A+IZA1',...
'IC4A+IZA2=IZBB+IZCC',...
'IZB*Z2LB+IC2B*2/YB=IC1B*2/YB',...
'I2C*Z2C=-IC2C*2/YC+IZC*Z2LC',...
'IZA1*m*Z2LA+IC2A*2/(m*YA)=IC1A*2/(m*YA)',...
'IC4A*2/((1-m)*YA)=IC2A*2/(m*YA)+IZA2*(1-m)*Z2LA',...
'I2EQBC*Z2EQBC+IZC*Z2LC=IZB*Z2LB',...
'I2B*Z2B+IC1B*2/YB',...
'I2C*Z2C+IC1C*2/YC',...
'I2A*Z2A+IC1A*2/(m*YA)',...
'IZB*Z2LB+(1-m)*Z2LA*IZA2=IZA1*m*ZL2A-I2EQAB*Z2EQAB',...
'IZA1*m*Z2LA=IZA2*(1-m)*Z2LA+IZC*Z2LC+I2EQAC*Z2EQAC',...
'IC4A/((1-m)*YA)=IC2C/YC'};
variables = {'m','I2A','I2B','I2C','I2EQAB','I2EQAC','I2EQBC',...
'IZA1','IC1A','IC2A','IZA2','IC4A','IC1B','IZB',...
'IC2B','IZBB','IZC','IC2C','IZCC'};
LL = solve(equations{:},variables{:})
Can you help me figure out what's going wrong?
Warning: 20 equations in 19 variables.
> In solve at 139
Warning: Explicit solution could not be found.
> In solve at 170
LL =
[ empty sym ]
I think that's self explanatory, if not check out the documentation related to DSOLVE where:
Diagnostics If dsolve cannot find an
analytic solution for an equation, it
prints the warning: Warning: Explicit
solution could not be found. and
returns an empty sym object.
solve() has issues with variable names in capital letters, as yours.
Please refer to http://www.mathworks.com/matlabcentral/newsreader/view_thread/303201
I tried reformatting the equations and inputting directly into the symbolic toolbox, and the solve function just spits out all the equations, so it cannot solve for those variables as the current equations stand.
Do you have any knowledge about the domains or constraints for all those variables? If you do I'd look at specifying all those, perhaps it would allow the solver to find a solution for you.
To get you quickly up and running in the symbolic toolbox, here's your equations reformatted to fit:
equations := {
I2B + I2EQAB = I22B + I2EQBC,
I2A = I2EQAB + I2EQAC + I22A,
I2C + I2EQBC + I2EQAC = I22C,
I22B = IZB + IC1B,
IZB = IC2B + IZBB,
I22C = -I2C * Z2C * YC / 2 + IZC,
IZC = IC2C + IZCC,
I22A = IC1A + IZA1,
IC4A + IZA2 = IZBB + IZCC,
IZB * Z2LB + IC2B * 2 / YB = IC1B * 2 / YB,
I2C * Z2C = -IC2C * 2 / YC + IZC * Z2LC,
IZA1 * m * Z2LA + IC2A * 2 / (m * YA) = IC1A * 2 / (m * YA),
IC4A * 2 / ((1 - m) * YA) = IC2A * 2 / (m * YA) + IZA2 * (1 - m) * Z2LA,
I2EQBC * Z2EQBC + IZC * Z2LC = IZB * Z2LB,
I2B * Z2B + IC1B * 2 / YB,
I2C * Z2C + IC1C * 2 / YC,
I2A * Z2A + IC1A * 2 / (m * YA),
IZB * Z2LB + (1 - m) * Z2LA * IZA2 = IZA1 * m * ZL2A - I2EQAB * Z2EQAB,
IZA1 * m * Z2LA = IZA2 * (1 - m) * Z2LA + IZC * Z2LC + I2EQAC * Z2EQAC,
IC4A / ((1 - m) * YA) = IC2C / YC
}:
variables := {
m, I2A, I2B, I2C, I2EQAB, I2EQAC ,I2EQBC,
IZA1, IC1A, IC2A, IZA2, IC4A, IC1B, IZB,
IC2B, IZBB, IZC, IC2C, IZCC
}:
solve(equations, variables)
To specify that all your known variables are real numbers, use this command:
assume(variables, Type::Real)
Also note that I count 36 unique variables (unless I made a mistake) in the equations, you'd be getting a huge list of "what-if's" for those equations if the solver was able to produce a result. I'd look at your equations and see if you could group them out and solve them in smaller sets.
Matlab, symbolic solve: solve()
I think has issues with symbolic variables who's names are more than one character.
a-z works, but anytime i try to solve something with two letters or more it just spits
back out the empty set.
For instance, something as simple as solve('xy*10 = 1', 'xy') doesn't work :(