I want to solve a system of equations containing a*x - excel

Is it possible to solve a system of three equations in Excel, that contain x*y??
Let's suppose that my unknowns are a,b,x
The equations are
a + b = 1
a * x - 20y = 0
10x * a - 20a + b = 0
Is there a way to express the multiplier that is one of my unknowns??

here you can take z=x*a then your equations become:
a + b = 1
z - 20y = 0
10z - 20a + b = 0
Now solve these equation using simple method given here. You get value of z and a. Now you can find value x. So finally you get value of a, b, z, y

Related

How to check if a point C(x3,y3) is falling between the straight line formed by two points A(x1,y1) & B(x2,y2)

I have two points A(x1,y1) & B(x2,y2) and I need to check if point c(x3,y3) falls on the straight line formed by point A & B.
A------C--------------------B then yes C is between A & B
A---------------------------B
C
in second case C isn't between A & B.
Using complex numbers, we define a similarity transformation that maps A to 0 and B to 1:
W = (Z - Za) / (Zb - Za)
Then Wc = (Zc - Za) / (Zb - Za) is a complex number that should have a zero or tiny imaginary value, and a real value between 0 and 1.
Make two vectors
cax = x1 - x3
cay = y1 - y3
cbx = x2 - x3
cby = y2 - y3
and check that angle between them is Pi:
Calculate dot and cross product of these vectors
dot = cax * cbx + cay * cby
cross = cax * cby - cay * cbx
Point C lies on segment AB if cross is zero and dot is negative
dot < 0
abs(cross) < eps
where eps is small value like 1e-6 to compensate floating point calculation errors.
if you are sure that all three point are aligned, you can use the dot product between vectors AC and AB, and the dot product between vectors BA and BC.
Reminder: Vector AB = (xB - xA, yB - yA)
Reminder: dot(AB, AC) = xABxAC + yAByAC
if dot(AB, AC) > 0, then it means C is in direction of B from A
if dot(BA, BC) > 0, then it means C is in direction of A from B
if both conditions above are satisfied, it means C is between A and B

String manipulation with dynamic programming

I have a problem where I have a string of length N, where (1 ≤ N ≤ 10^5). This string will only have lower case letters.
We have to rewrite the string so that it has a series of "streaks", where the same letter is included at least K (1 ≤ K ≤ N) times in a row.
It costs a_ij to change a single specific letter in the string from i to j. There are M different possible letters you can change each letter to.
Example: "abcde" is the input string. N = 5 (length of "abcde"), M = 5 (letters are A, B, C, D, E), and K = 2 (each letter must be repeated at least 2 times) Then we are given a M×M matrix of values a_ij, where a_ij is an integer in the range 0…1000 and a_ii = 0 for all i.
0 1 4 4 4
2 0 4 4 4
6 5 0 3 2
5 5 5 0 4
3 7 0 5 0
Here, it costs 0 to change from A to A, 1 to change from A to B, 4 to change from A to C, and so on. It costs 2 to change from B to A.
The optimal solution in this example is to change the a into b, change the d into e, and then change both e’s into c’s. This will take 1 + 4 + 0 + 0 = 5 moves, and the final combo string will be "bbccc".
It becomes complicated as it might take less time to switch from using button i to an intermediate button k and then from button k to button j rather than from i to j directly (or more generally, there may be a path of changes starting with i and ending with j that gives the best overall cost for switching from button i ultimately to button j).
To solve for this issue, I am treating the matrix as a graph, and then performing Floyd Warshall to find the fastest time to switch letters. This will take O(M^3) which is only 26^3.
My next step is to perform dynamic programming on each additional letter to find the answer. If someone could give me advice on how to do this, I would be thankful!
Here are some untested ideas. I'm not sure if this is efficient enough (or completely worked out) but it looks like 26 * 3 * 10^5. The recurrence could be converted to a table, although with higher Ks, memoisation might be more efficient because of reduced state possibilities.
Assume we've recorded 26 prefix arrays for conversion of the entire list to each of the characters using the best conversion schedule, using a path-finding method. This lets us calculate the cost of a conversion of a range in the string in O(1) time, using a function, cost.
A letter in the result can be one of three things: either it's the kth instance of character c, or it's before the kth, or it's after the kth. This leads to a general recurrence:
f(i, is_kth, c) ->
cost(i - k + 1, i, c) + A
where
A = min(
f(i - k, is_kth, c'),
f(i - k, is_after_kth, c')
) forall c'
A takes constant time since the alphabet is constant, assuming earlier calls to f have been tabled.
f(i, is_before_kth, c) ->
cost(i, i, c) + A
where
A = min(
f(i - 1, is_before_kth, c),
f(i - 1, is_kth, c'),
f(i - 1, is_after_kth, c')
) forall c'
Again A is constant time since the alphabet is constant.
f(i, is_after_kth, c) ->
cost(i, i, c) + A
where
A = min(
f(i - 1, is_after_kth, c),
f(i - 1, is_kth, c)
)
A is constant time in the latter. We would seek the best result of the recurrence applied to each character at the end of the string with either state is_kth or state is_after_kth.

How to plot 3D surface for implicit functions in excel?

I have the equation: sqrt(2)*cos(xy) = (z/sqrt(2)) + sin(z) - cos(z)
with following interval
-1 <= x <= 1 and dx = 0.1
0 <= y <= 1.5 and dx = 0.05
that I need to plot the 3D surface of on excel.
I can't simplify the equation interms of z so how can I calculate the possible values in the matrix form for the given x and y values?
I am following this tutorial: https://www.youtube.com/watch?v=jUoo_7KQfO0 but I don't know how to write the above equation in terms of z.
First of all your number of values of x/y looks different, x has 20 values, while y has 30
I think it should be
-1 <= x <= 1 and dx = 0.1
0 <= y <= 1 and dx = 0.05
Or
-1 <= x <= 2 and dx = 0.1
0 <= y <= 1.5 and dx = 0.05
Then about z, you can find it in excel using Goal Seek
with formulae
In above screenshot using Goal Seek you have to find value of (z/sqrt(2)) + sin(z) - cos(z) (column F) where it is equal to value of sqrt(2)*cos(xy) (column E) by changing the values of Z(column C)
As an example: For first value you would enter like below
After you have generated all z you can select all the data of x, y and z and insert the 3d surface graph.

Table with 4 variable columns

I'm sure this is simple for all of you, but I'm new here. How do I create a formula or code that can output all of the potential scenarios for this type of array below? Basically, max is 60, min is 0, but I'm unsure how to make Excel spit out a table that represents this.
Solution:
Doing it with Excel formulas alone, while theoretically possible, is incredibly computationally demanding and crashed Excel when I was trying to do so. You can do this fairly easy with VBA though.
Create a VBA module, drop these two snippets in, press play, and wait for a few seconds to a minute while the code runs. The code is not the most efficient, but it is probably the simplest algorithm to understand.
Public Sub comb4()
Dim a, b, c, d, n, r, x As Integer
x = 60
a = x
Do While a >= n
b = x - a
Do While b >= n
c = x - a - b
Do While c >= n
d = x - a - b - c
Do While d >= n
If sumToZero(-x, a, b, c, d) Then
r = r + 1
Cells(r, 1).Value = a
Cells(r, 2).Value = b
Cells(r, 3).Value = c
Cells(r, 4).Value = d
End If
d = d - 1
Loop
c = c - 1
Loop
b = b - 1
Loop
a = a - 1
Loop
End Sub
Public Function sumToZero(ParamArray intNums())
For x = LBound(intNums) To UBound(intNums)
y = y + intNums(x)
Next x
If y = 0 Then sumToZero = True
End Function
Code explanation:
x is the max that you defined, while n is the min you defined.
r is a counter which helps us track what row to print to.
Since we always want to count down to 0 for each column's sub-permutations, each of our Do While loops will count from the theoretical maximum value down to 0.
The loop structure is nested so that each time we hit -1 in a column N we instead leave the loop, go into the loop one level higher, and decrease the value in column M by 1. The value in N is reset when we start the next instance of the loop for M.
Between each value change we need to check to see if the result is a valid solution. We pass the (negative) max and all 4 variables we are looping to a function which sums the values and returns true if the variables are equal to the max. When the function is true, we go to the next row in Excel and print the four values.

Simple python and need explanation

m = 0
for x in range (4,6):
for y in range (2,4):
m = m + x + y
print (m)
ANSWER: 28
not sure how this is? Excluding the last number in the range, I thought it should be 14. I add it up on paper and cannot understand what I am doing wrong.
That loop is equivalent to:
m = 4+2 + 4+3 + 5+2 + 5+3
And, that sum is 28.
(In the outer loop, x takes on the values 4 and 5. In the inner loop, y takes on values 2 and 3.)

Resources