I am trying to solve a set of two equations for two complex variables in terms of the other terms.
I put the two equations in a list and tried to solve for both the variables together, but this kept giving me incorrect results.
However, if I can manually separate out the terms in each equation and substitute them, I'm able to obtain the right answer. This is extremely puzzling and I don't understand if this is a bug in maxima or something's wrong in what I'm doing. Any guidance/comments will be appreciated.
Here's a minimal example that does what I'm speaking about (along with final output). In the following, sol1 gives me incorrect solutions and sol2 gives me the right solution.
(%i2) kill(all)$
declare([R0, a, b, x, y], complex)$
eqs:[(2*%i*x*ω+24*R0^2*conjugate(R0)*b^2*conjugate(b)-48*R0^2*conjugate(R0)*a*b*conjugate(b)+24*R0^2*conjugate(R0)*a^2*conjugate(b)-24*R0^2*conjugate(R0)*conjugate(a)*b^2+48*R0^2*conjugate(R0)*a*conjugate(a)*b+%i*x-2*x-24*R0^2*conjugate(R0)*a^2*conjugate(a)), (6*%i*y*ω+8*R0^3*b^3-24*R0^3*a*b^2+24*R0^3*a^2*b+3*%i*y-2*y-8*R0^3*a^3)]$
(%i4) sol1:factor(solve(eqs, [x, y])[1])$
sol2:factor([solve(eqs[1],x)[1],solve(eqs[2],y)[1]])$
(%i6) factor(subst(sol1,eqs));
factor(subst(sol2,eqs));
(%o5) [0,-24*R0^3*(b-a)^3*(2*%i*ω+%i-1)]
(%o6) [0,0]
Here's a screenshot on wxmaxima, if that helps you to see better :
Related
I was trying to sharpen my skills by solving the Codality problems. I reached this one: https://codility.com/programmers/lessons/9-maximum_slice_problem/max_double_slice_sum/
I actually theoretically understand the solution:
Use Kadane's Algorithm on the array and store the sum at every index.
Reverse the array and do the same.
Find a point where the sum of both is max by looping over both result sets one at a time.
The max is the max double slice.
My question is not so much about how to solve the problem. My question is about how does one imagine that this will be way in which this problem can be solved. There are at-least 3 different concepts that need to be made use of:
The understanding that if all elements in the array are positive, or negative it is a different case than when there are some positive and negative elements in the array.
Kadane's Algorithm
Going over the array forward and reversed.
Despite all of this, Codality has tagged this problem as "Painless".
My questions is am I missing something? It seems hard that I would be able to solve this problem without knowing some of these concepts.
Is there a technique where I can start from scratch and very basic concepts and work my way up to the concepts required to solve this problem. Or is it that I am expected to know these concepts before even starting the problem?
How can I prepare my self to solve such problems where I don't know the required concepts in the future?
I think you are overthinking the problem, that's why you find it more difficult than it is:
The understanding that if all elements in the array are positive, or negative it is a different case than when there are some positive and negative elements in the array.
It doesn't have to be a different case. You might be able to come up with an algorithm that doesn't care about this distinction and works anyway.
You don't need to start by understanding this distinction, so don't think about it until or even if you have to.
Kadane's Algorithm
Don't think of an algorithm, think of what the problem requires. Usually that 10+ paragraph problem statement can be expressed in much less.
So let's see how we can simplify the problem statement.
It first defines a slice as a triplet (x, y, z). It's defined at the sum of elements starting at x+1, ending at z-1 and not containing y.
Then it asks for the maximum sum slice. If we need the maximum slice, do we need x and z in the definition? We might as well let it start and end anywhere as long as it gets us the maximum sum, no?
So redefine a slice as a subset of the array that starts anywhere, goes up to some y-1, continues from y+1 and ends anywhere. Much simpler, isn't it?
Now you need the maximum such slice.
Now you might be thinking that you need, for each y, the maximum sum subarray that starts at y+1 and the maximum sum subarray that ends at y-1. If you can find these, you can update a global max for each y.
So how do you do this? This should now point you towards Kadane's algorithm, which does half of what you want: it computes the maximum sum subarray ending at some x. So if you compute it from both sides, for each y, you just have to find:
kadane(y - 1) + kadane_reverse(y + 1)
And compare with a global max.
No special cases for negatives and positives. No thinking "Kadane's!" as soon as you see the problem.
The idea is to simplify the requirement as much as possible without changing its meaning. Then you use your algorithmic and deductive skills to reach a solution. These skills are honed with time and experience.
Consider the relations: edge(X,Y), Red(X,Y), Blue(X,Y). These relations are representing a graph whose edges can be colored red or blue(or no color).
provide safe datalog rules(with negation if necessary) for the following queries.
Q1. find the pairs of nodes X and Y where there is path (a sequence of linked edges) from X to Y ?
my attempt:- reachable(X,Y) :- edge(X,Y)
reachable(X,Y) :- edge(X,Z), reachable(Z,Y)
Q2. Find the pairs of nodes X and Y where there is path (a sequence of linked edges) of even length from X to Y with alternating red and blue colors?
my attempt:
I have made odd even datalog program and a red/blue program, but don't know how to combine the both to get even length alternate red/blue node
ODD(x,y):- edge(x,y)
ODD(x,y):- edge(x,z), EVEN(z,y)
EVEN(x,y):- edge(x,z), ODD(z,y).
path(X,Y) :- Red(X,Y)
path(X,Y) :- path(X,Z), Blue(Z,W), path(W,Y)
From your questions I get the impression that you're trying to answer these assignments without testing your potential solutions. That's a very difficult way to work. I would strongly suggest to make little examples to test whether your solution is correct and run it in a Datalog engine (easiest is something online like http://www.iris-reasoner.org/demo or https://developer.logicblox.com/playground/ ).
In this particular case, it is easy to see that if you have an edge("a", b"), edge("b", c") and edge("c", "d"), that your solution will not find a path from "a" to "d".
This query can only be solved with recursion. This path query is pretty basic recursion, search for ancestor or transitive closure.
I have a large sparse linear system generated as a part of PDE solution for flows in the form Ax=b. The condition number of matrix A is very bad - of the order 3000!. But I get expected solutions with direct solvers. So, now I want to precondition the matrix so that I can use iterative solvers and use the sparseness. I have tried Jacobi preconditioner, but it does not work well as the matrix is not diagonally dominant. I need some help in proceeding further:
1) Imagine I get an approximate solution for x (generated by one run of biconjugate gradient solver). Now can I get "inverse of A" (for preconditioning) from this, seems like it must be possible but I am unable to figure out how! i.e knowing x and b can I calculate the A inverse (which may be used as preconditioner!).
2) Any other way of preconditioning which you feel would be worth a try?
3) Any way to circumvent pre-conditioning for iterative schemes for bad condition number systems?
Thanks a lot in advance for any help. Any comments are welcome.
I am solving three non-linear equations in three variables (H0D,H0S and H1S) using FindRoot. In addition to the three variables of interest, there are four parameters in these equations that I would like to be able to vary. My parameters and the range in which I want to vary them are as follows:
CF∈{0,15} , CR∈{0,8} , T∈{0,0.35} , H1R∈{40,79}
The problem is that my non-linear system may not have any solutions for part of this parameter range. What I basically want to ask is if there is a smart way to find out exactly what part of my parameter range admits real solutions.
I could run a FindRoot inside a loop but because of non-linearity, FindRoot is very sensitive to initial conditions so frequently error messages could be because of bad initial conditions rather than absence of a solution.
Is there a way for me to find out what parameter space works, short of plugging 10^4 combinations of parameter values by hand and playing around with the initial conditions and hoping that FindRoot gives me a solution?
Thanks a lot,
I have a database of items. They are for cars and similar parts (eg cam/pistons) work better than others in different combinations (eg one product will work well with another, while another combination of 2 parts may not).
There are so many possible permutations, what solutions apply to this problem?
So far, I feel that these are possible approaches (Where I have question marks, something tells me these are solutions but I am not 100% confident they are).
Neural networks (?)
Collection-based approach (selection of parts in a collection for cam, and likewise for pistons in another collection, all work well with each other)
Business rules engine (?)
What are good ways to tackle this sort of problem?
Thanks
The answer largely depends on how do you calculate 'works better'?
1) Independent values
Assuming that 'works better' function f of x combination of items x=(a,b,c,d,...) and(!) that there are no regularities that can be used to decide if f(x') is bigger or smaller then f(x) knowing only x, f(x) and x' (which could allow to find the xmax faster) you will have to calculate f for all combinations at least once.
Once you calculate it for all combinations you can sort. If you will need to look up data in a partitioned way, using SQL/RDBMS might be a good approach (for example, finding top 5 best solutions but without such and such part).
For extra points after calculating all of the results and storing them you could analyze them statistically and try to establish patterns
2) Dependent values
If you can establish some regularities (and maybe you can) regarding the values the search for the max value can be simplified and speeded up.
For example if you know that function that you try to maximize is linear combination of all the parameters then you could look into linear programming
If it is not...