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

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

Related

Weird error Matlab with piecewise elements in matrix

I'm trying to solve a differential equation that has the form Y'(t)=A(t)*Y(t), where Y and Y' is a column with 4 elements, A is a 4x4 matrix. In the A(t) matrix I'm using the functions m(t) and f(t) to compute each value of the matrix. However, when I put a simple value to m(t) and f(t) (ex: a constant value or a t^2...) the function solvedPmWithTime returns a 4x1 matrix, which is what I expect, but when I use the m(t) and /or function f(t) that I want, which is computed by the compute_m_and_f function, it returns a 1x1 matrix. I can't find my error. If someone could help it would be very much appreciated :). Here are the codes of the functions and the code of the live script that I use to compute the differential equation:
function [m,f] = compute_m_and_f()
syms m(t) f(t)
Bm =600000;
sigmam =2.5;
tm =6;
tf =6;
sigmaf = 2;
Bf = 600000;
eqnM = diff(m,t) == Bm / sqrt(2*pi*sigmam^2)*exp(-((t-tm)^2)/(2*sigmam^2));
condM = m(0)==0;
eqnF = diff(f,t) == Bf / sqrt(2*pi*sigmaf^2)*exp(-((t-tf)^2)/(2*sigmaf^2));
condF = f(0)==0;
M(t) = dsolve(eqnM, condM);
F(t) = dsolve(eqnF, condF);
taum = 4;
tauf = 5;
m(t) = piecewise(t>taum, M(t)-M(t-taum),M(t));
f(t) = piecewise(t>tauf, F(t)-F(t-taum),F(t));
end
function solvedPmWithTime= solvedPmWithTime(~, y)
[m, f] = compute_m_and_f;
alpha = 480;
beta = 0.0011;
sigma = 0.0634;
epsilon = 0.0725;
a = (alpha * (f + m)) / (1 + alpha * beta * (f + m));
b11 =- (1 - (m / (f + m)) ^ sigma);
b12 = (1 - (f / (f + m)) ^ epsilon);
b13 = (1 - (f / (f + m)) ^ epsilon);
b14 = (1 - (f / (f + m)) ^ epsilon);
b21 = (1 - (m / (f + m)) ^ sigma);
b22 = -1;
b23 = 0;
b24 = 0;
b31 = 0;
b32 = (f / (f + m)) ^ epsilon;
b33 = -1;
b34 = 0;
b41 = 0;
b42 = 0;
b43 = (f / (f + m)) ^ epsilon;
b44 =- (1 - (f / (f + m)) ^ epsilon);
b = [b11, b12, b13, b14; b21, b22, b23, b24; b31, b32, b33, b34; b41, b42, b43, b44];
A = a * b;
solvedPmWithTime = A * y;
end
clear all
rho = 6;
Bf = 600000;
Pm1_0 = 0;
Pm2_0 = 0;
Pm3_0 = 0;
Pf_0 = 3600;
[t, Pm] = ode45(#solvedPmWithTime, [0, 100], [Pm1_0; Pm2_0; Pm3_0; Pf_0]); %this returns an error because the size of the matrix is not 4x1
Pm1 = Pm(:, 1);
Pm2 = Pm(:, 2);
Pm3 = Pm(:, 3);
Pf = Pm(:, 4);
hold off
plot(t, Pm1, t, Pm2, t, Pm3, t, Pf)
legend('Pm1', 'Pm2', 'Pm3', 'Pf')
n = solvedPmWithTime([0, 100], [Pm1_0; Pm2_0; Pm3_0; Pf_0]);
size(n)

Extract intermediate parameter values from an ODE function?

I want to get extract intermediate parameter values from below ODE function. Can someone figure out how to extract those values from the ode solver.
I want to get values of "a, b,s,& w" apart from the main outputs of the ode solver. I tried to modify return option in the function, but that doesn't work.
Be kind to explain by providing sample codes as I am bit new to python.
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# parameters
S = 0.0001
M = 30.03
K = 113.6561
Vr = 58
R = 8.3145
T = 298.15
Q = 0.000133
Vp = 0.000022
Mr = 36
Pvap = 1400
wf = 0.001
tr = 1200
mass = 40000
# define t
time = 14400
t = np.arange(0, time + 1, 1)
# define initial state
Cv0 = (mass / Vp) * wf # Cv(0)
Cr0 = (mass / Vp) * (1 - wf)
Cair0 = 0 # Cair(0)
# define function and solve ode
def model(x, t):
C = x[0] # C is Cair(t)
c = x[1] # c is Cv(t)
a = Q + (K * S / Vr)
b = (K * S * M) / (Vr * R * T)
s = (K * S * M) / (Vp * R * T)
w = (1 - wf) * 1000
Peq = (c * Pvap) / (c + w * c * M / Mr)
Pair = (C * R * T) / M
dcdt = -s * (Peq - Pair)
if t <= tr:
dCdt = -a * C + b * Peq
else:
dCdt = -a * C
return [dCdt, dcdt]
x = odeint(model, [Cair0, Cv0], t)
C = x[:, 0]
c = x[:, 1]

Boolean expression F = x'y + xyz':

Using DeMorgan's theorem show that:
a. (A + B)'(A' +B)' = 0
b. A + A'B + A'B' = 1
Boolean expression F = x'y + xyz':
Derive an algebraic expression for the complement F'
Show that F·F' = 0
Show that F + F' = 1
Please Help me
Assuming you know how DeMorgan's law works and you understand the basics of AND, OR, NOT operations:
1.a) (A + B)'(A' + B)' = A'B'(A')'B' = A'B'AB' = A'AB'B' = A'AB' = 0 B' = 0.
I used two facts here that hold for any boolean variable A:
AA' = 0 (when A = 0, A' = 1 and when A = 1, A' = 0 so (AA') has to be 0)
0A = 0 (0 AND anything has to be 0)
1.b) A + A'B + A'B' = A + A'(B + B') = A + A' = 1.
I used the following two facts that hold for any boolean variables A, B and C:
AB + AC = A(B + C) - just like you would do with numeric variables and multiplication and addition. Only here we work with boolean variables and AND (multiplication) and OR (addition) operations.
A + A' = 0 (when A = 0, A' = 0 and when A = 1, A' = 0 so (A + A') has to be 1)
2.a) Let's first derive the complement of F:
F' = (x'y + xyz')' = (x'y)'(xyz')' = (x + y')((xy)' + z) = (x + y')(x' + y' + z) = xx' + xy' + xz + x'y' + y'y' + y'z = 0 + xy' + xz + x'y' + y' + y'z = xy' + xz + y'(x + 1) + y'z = xy' + xz + y' + y'z = xy' + xz + y'(z + 1) = xy' + y' + xz = y'(x + 1) = xz + y'.
There is only one additional fact that I used here, that for any boolean variables A and B following holds:
A + AB = A(B + 1) = A - logically, variable A completely determines the output of such an expression and part AB cannot change the output of entire expression (you can check this one with truth tables if it's not clear, but boolean algebra should be enough to understand). And of course, for any boolean variable A + 1 = A.
2.b) FF' = (x'y + xyz')(xz + y') = x'yxz + x'yy' + xyz'xz + xyz'y'.
x'yxz = (xx')yz = 0xz = 0
xyy'= x0 = 0
xyz'xz = xxy(zz') = xy0 = 0
xyz'y' = xz'(yy') = xz'0 = 0
Therefore, FF' = 0.
2.c) F + F' = x'y + xyz' + xz + y'
This one is not so obvious. Let's start with two middle components and see what we can work out:
xyz' + xz = x(yz' + z) = x(yz' + z(y + y')) = x(yz' + yz + y'z) = x(y(z + z') + y'z) = x(y + y'z) = xy + xy'z.
I used the fact that we can write any boolean variable A in the following way:
A = A(B + B') = AB + AB' as (B + B') evaluates to 1 for any boolean variable B, so initial expression is not changed by AND-ing it together with such an expression.
Plugging this back in F + F' expression yields:
x'y + xy + xy'z + y' = y(x + x') + y'(xz + 1) = y + y' = 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.

Shortening a transfer function in 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))