Set up system of linear equations and solve - equation

i need to set up a system of linear equations and solve it.
The calculations are based on a graph and are always of the same format.
I need ideas how to solve my problem efficiently...
At first I create all necessary equations. Here is an example:
q = 4,9 + r
r = 2,3 + 0,03q + 0,11d + 0,85(1 + r)
d = 15,3 + 0,02q + 0,74r
This step is already done. My program creates this formulas. My problem is now, what is the most efficient way to calculate the values?
I need to prepare the equations to be able to use them in a matrix solver. Hence, i have to eliminate the brackets and combine the values...
I thought of combining multiple java libraries to reach the goal. At first I wanted to use a simplifier to simplify all equations and finally a matrix solver to calculate the values. Here are my thoughts:
Step 1: Eliminate brackets if necessary)
q = 4,9 + r
r = 2,3 + 0,03q + 0,11d + 0,85 + 0.85r
d = 15,3 + 0,02q + 0,74r
Step 2: Combine values)
q = 4,9 + r
r = 3,15 + 0,03q + 0,11d + 0.85r
d = 15,3 + 0,02q + 0,74r
Step 3: Prepare matrix)
-4,9 = -q + r
-3,15 = -r + 0,03q + 0,11d + 0,85r
-15,3 = -d + 0,02q + 0,74r
Step 3.2: Combine values)
-4,9 = -q + r
-3,15 = -0,15r + 0,03q + 0,11d
-15,3 = -d + 0,02q + 0,74r
Step 3.3: Sort values)
-4,9 = -q + r
-3,15 = 0,03q - 0,15r + 0,11d
-15,3 = 0,02q + 0,74r -d
Step 3.4: Matrix structure)
-4,9 = -1 1 0
-3,15 = 0,03 -0,15 0,11
-15,3 = 0,02 0,74 -1
And now I can use a matrix solver like jama. There are several steps that have to be performed. But whats the most efficient way without reinventing the wheel?
Thanks in advance.

Related

How to prove (x+y)/z + (y+z)/x + (x+z)/y>=6 when x,y,z>0

This question actually had two parts. In the first part I had to prove that a + 1/a >=2. I proved it by rearranging it to (a-1)^2 >= 0, which is always true.
So, I thought the second problem would require a similar method.
(x+y)/z + (y+z)/x + (x+z)/y >=6, where x,y,z>0
But I cant figure it out.
I've tried simplifying it and factoring it for ideas but I've got nothing.
Once you know that a + 1/a >= 2, the second part is easy. Define:
a := x/z, b := y/z, c := y/x
and now
(x+y)/z + (y+z)/x + (x+z)/y = x/z + y/z + y/x + z/x + x/y + z/y
= a + b + c + 1/a + 1/c + 1/b
>= 2 + 2 + 2
= 6

Why does the fibonacci recursive sequence work?

I am wondering why this Fibonacci recursive function works:
int fibRec(int n)
{
if ((n == 1) || (n == 0))
{
return n;
}
int i = fibRec(n - 1) + fibRec(n - 2);
return i;
}
I understand what the Fibonacci sequence is and I understand what a recursive function does and how this function is working. I'm just having troubles understanding why it works. I know that when you break it down, you are essentially adding a bunch of 0s and 1s, as this image depicts.
fibonacci recursive
But why is it that when I pass a 5 to the function and all the 0 and 1s are added that it will equal the 5th sequence number in the Fibonacci sequence? I've seen this question asked before but never really explained. The responses are all just "because recursion". Yes, I know what a recursive function is and how this one is working. But WHY does this recursive function give you the correct Fibonacci sequence number?
In the Fibonacci sequence the first two numbers are zero and one. Every number after these is the sum of the previous 2 numbers. So the first few numbers are
F(0) ≡ 0
F(1) ≡ 1
F(2) = F(1) + F(0) = 1 + 0 = 1
F(3) = F(2) + F(1) = 1 + 1 = 2
F(4) = F(3) + F(2) = 2 + 1 = 3
F(5) = F(4) + F(3) = 3 + 2 = 5
F(6) = F(5) + F(4) = 5 + 3 = 8
...
F(n) = F(n - 1) + F(n - 2) ∀ n > 1
Therefore when we calculate a Fibonacci number recursively we have to practice the following logical procedure (in pseudo-code out of respect to StackOverflow).
Integer NthFibonacci(Integer n) {
if (n < 0) {
return undefined;
} else if (n < 2) {
return n;
} else {
return NthFibonacci(n - 1) + NthFibonacci(n - 2);
}
}
I'm sure you know all this but I think it will help my explanation to have this part as a reference.
Where the Ones and Zeros Come In
The best way to explain this is probably with an example.
Imagine that, as above, we are trying to recursively calculate F(6). Try following the procedure given above. Remember that we will perform recursion only if n > 1.
First we start with F(6) = F(5) + F(4).
Then we find F(5) = F(4) + F(3).
Then we find F(4) = F(3) + F(2).
Then we find F(3) = F(2) + F(1).
Then we find F(2) = F(1) + F(0).
This is where things start to work out!
We have now gotten F(2) in terms of F(1) ≡ 1 and F(0) ≡ 0 (both of which are known), and so we are able to calculate an actual value instead of performing more recursion.
We can now find F(2) = F(1) + F(0) = 1 + 0 = 1.
NOTICE THE 1 AND 0 Those are what people are talking about when they say the whole thing comes down to ones and zeros. Every time we recurse down to find a base value we will end up finding F(2) = 1 + 0. This leads to more ones and zeros as we move back up our recursion tree being able to calculate higher and higher values, as follows.
F(3) = F(2) + F(1) = (1 + 0) + 1
F(4) = F(3) + F(2) = ((1 + 0) + 1) + (1 + 0)
F(5) = F(4) + F(3) = (((1 + 0) + 1) + (1 + 0)) + ((1 + 0) + 1)
F(6) = F(5) + F(4) = ((((1 + 0) + 1) + (1 + 0)) + ((1 + 0) + 1)) + (((1 + 0) + 1) + (1 + 0))
Now if you add up all the 1's you get a sum of 8, and so F(6) = 8, which is correct!
This is how it works, and this is how it breaks down to ones and zeros.
Remember, recursion works by breaking down the problem till we know what the answer is, and then building it up from there.
What do we know about the fibonacci sequence?
We know that when:
x = 1
and
x = 0
That that is the lowest it goes. That is an important key. Because when x = 0 we are really doing 0 + 0 and when x = 1 we are really doing 0 + 1. Now start at the top.
0,1,1,2,3,5,8,13...
If we are at 13. what is 13? Why simply 5 + 8 right? So That is where
int i = fibRec(n - 1) + fibRec(n - 2);
comes from. Because these are going to branch out lower and lower till we are at a base case for each one.
This is the recursive calling. Because now the method is going to go back to the stack and call fibRec again. You will notice that (n-1) and (n-2) are both added together and set to i. This is so that we don't lose the value. because of the + sign the stack then ends up returning more and more (n-1)s and (n-2)s until we are at the base case. I hope all of this makes sense. Thinking recursively can be very difficult. Here is a a visual representation from top to bottom of what it would look like.
In short. This just keeps adding the previous fibonacci sequences to the current one until it gets to the current loop.

Simplifying a logic function using boolean algebra

I'm taking a class on digital logic and I am having a hard time with boolean algebra and simplifying logic functions with it. I have tried answering this problem several times and I keep coming to the answer "1", which I feel is absolutely wrong.
The question is
Consider the logic function f(a,b,c) = abc + ab'c + a'bc + a'b'c + ab'c'. Simplify f using Boolean algebra as much as possible.
I have tried solving it several ways using the boolean identities given in my textbook and from lecture, but I keep coming to something like c + 1 which is equivalent to 1, which I don't feel is the correct answer considering the next question in the problem.
Here is my last attempt:
f(a,b,c) = abc + ab'c + a'bc + a'b'c + ab'c'
= a(bc + b'c + b'c') + a'(bc + b'c) # Distributive, took out the a and the a' separately.
= (a + a')((bc + b'c + b'c') + (bc + b'c)) # Distributive(?), took out the a and a' together (This is probably where I screwed up).
= (1)((c + b'c') + c) # a + a' = 1; bc + b'c = c (Combining).
= c + b'c' + c # cleaned up a little.
= c + b'c' # c + c = c.
= c + (b' + c') # b'c' = b' + c' (DeMorgan's Theorem).
= 1 + b' # c + c' = 1.
= 1 # 1 + b' = 1
This feels absolutely wrong to me, and the next question asks me to make the logic circuit for it, which I don't think is possible.
Can anyone help/walk me through what I am doing wrong? I would really appreciate it. :(
(P.S. I used code formatting, I apologize if this is annoying to some.)
By this table:
A 1 1 1 1 0 0 0 0
B 1 1 0 0 1 1 0 0
C 1 0 1 0 1 0 1 0
Y 1 0 1 1 1 0 1 0
Y=ab'+c
I've got it :D
f(a,b,c) = abc + ab'c + a'bc + a'b'c + ab'c'
= a(bc + b'c + b'c') + a'(bc + b'c)
= a(c(b + b') + b'c') + a'(c(b + b'))
= a(c * 1 + b'c') + a'(c * 1)
= a(c + b'c') + a'c
= a(c'(b'c')')' + a'c
= a(c'(b + c))' + a'c
= a(c'b +cc')' + a'c
= a(c'b)' + a'c
= a(c+b') + a'c
= ac + ab' + a'c
= c(a + a') + ab'
= ab' + c

Mathcad 14: "pattern match exception" when solving equation with more unknowns

I'm trying to solve an equation with 5 unknowns in Mathcad 14. My equations look like this:
Given
0 = e
1 = d
0 = c
-1 = 81a + 27b + 9c + 3d + e
0 = 108a + 27b + 6c + d
Find(a,b,c,d,e)
Find(a,b,c,d,e) is marked as red and says "pattern match exception". What is the problem?
In mathcad you need to do something similar to:
c:=0
d:=1
e:=0
a:=1
b:=1
Given
81*a + 27*b + 9*c + 3*d + e = -1
108*a + 27*b + 6*c + d = 0
Find(a,b,c,d,e) = (0,0,0,0,-1)
Now, what I have done here is to define the variables BEFORE the Solve Block (Given...Find), you have to give initial values which you think are close to the solution you require in order for the iteration to succeed.
Tips: To get the equals sign in the Solve Block, use ctrl and '='. If your looking to solve for 5 unknowns then you need 5 equations, the original post looked like you knew 3 of the variables and were looking for a and b, in this case you would do the following:
c:=0
d:=1
e:=0
a:=1
b:=1
Given
81*a + 27*b + 9*c + 3*d + e = -1
108*a + 27*b + 6*c + d = 0
Find(a,b) = (0.111,-0.481)
This has held c, d and e to their original values and iterated to solve for a and b only.
Hope this helps.

Boolean Logic Design - Reduction

I have the following function to be reduced/simplified.
F(A,B,C,D) = BC + (A + C'D') where ' denotes the complement
Here's my solution:
= BC + (A + C'D')'
= BC + (A + (C+D)
= BC + (A + C + D)
= BC + C + A + D
= C(B + 1) + A + D
= C*1 + A + D
= C + A + D
Is this correct?
As in traditional algebra, if you do something to one side of the equation, you must do it to the other side, including complementing. Here we state the original equation:
F'(A,B,C,D) = BC + (A + (CD)')
Since we have F' instead of F, my intuition tells me to complement both sides, but first I distribute the complement in the term (CD)' to make life easier in the long run:
F' = BC + (A + (C'+ D'))
Now we can complement both sides of the equation:
1: F = '(BC)'(A + (C'+ D')) The OR becomes AND after distributing complement
Now let's distribute the complements inside just to see what we get:
2: F = (B'+ C')(A'(CD))
Now we can just distribute the right term (A'(CD)) over the two terms being OR'ed:
3: F = B' (A'(CD)) + C' (A'(CD))
We see that the right term goes away since we have a CC' and thus we are left with:
4: F = A'B'CD
Hopefully I didn't make a mistake. I know you've found the answer, but others reading this might have a similar question and so I did it out to save duplicate questions from being asked. Good Luck!