In FFMpeg I use as filter
lutyuv="y=0.000018712*val*val+0.0027334*val+1.3141:u=gammaval(1.09)"
This works well. Now I want to calculate u value as a function of calculated y, something like u=1.1*previous_calculated_y*val. How can I access previously calculated y value in formula for u? Or how can I access y information in formula for u?
Example: If y value was zero I would like to get for u = 1.3141*val.
I googled and found nothing.
lutyuv="y=0.000018712*val*val+0.0027334*val+1.3141:u=gammaval(1.09)"
Related
I am am mathmatica notebook to find an analytical solution to the follow constrained optimization problem:
Max y^(1-b)(x^b(1-a(x/(x+1)))) s.t. M = Px+qy
x,y
I have tried the following code:
Maximize[{y^(1-b)(x^b(1-a(x/(x+1)))), M==Px+qy}, {x,y}]
and in returns the same function as an output. In the function a, b, M, P, and q are all parameters. I have also tried assigning the parameters arbitrary values to test to see if mathmatica is not sure how to deal with the parameters. I used to following code:
Maximize[{y^(1-0.5)(x^0.5(1-0.75(x/(x+1)))), 1000=5x+5y},{x,y}]
and it returns the same function. However, if I remove the constraint it will solve the optimization problem.
Maximize[{y^(1-0.5)(x^0.5(1-0.75(x/(x+1))))},{x,y}]
{7.2912*^59,{x->2.89727*^60,y->2.93582*^60}}
I am not sure what to do. After reading about constrained optimization problem the syntax appears to be correct. Sorry, it this question is really basic I am very new to mathmatica, also since I am using a notebook I could not past the output from the first two lines in.
The constraint is incorrectly specified, it should be 1000 == 5 x + 5 y. Maximize works better with exact numbers.
Maximize[{Rationalize[y^(1 - 0.5) (x^0.5 (1 - 0.75 (x/(x + 1))))],
1000 == 5 x + 5 y}, {x, y}] // N
(* {25.7537, {x -> 96.97, y -> 103.03}} *)
I have an equation on the form A^n*b =e= c where A is a matrix and b & c are column vectors.
n is a fixed number for my model determined by a constant. It will most likely be in the hundreds and be changed for different solutions.
A is a matrix of variables, b & c are constants.
How can I formulate A^n*b =e= c in gams?
Optionally: the model that lead me to this is that I have a graph with a connectivity matrix con(x,x2) denoting the connectivity between x and x2 when x and x2 are connected. I would like to calculate the connection between 2 arbitrary nodes, the connectivity between 2 nodes x to x2 is the sum of the connectivity for all paths from x to x2. the connectivity for a path is the product of all connections along the path. Is there a smarter way to formulate this constraint so that I don't have to do matrix exponentiation?
A is not symmetric or invertible but is positive Semidefinite.
You need to define your data in terms of sets and parameters first. Follow this link for more information about the data structure in GAMS: http://www.gams.com/latest/docs/userguides/userguide/_u_g__data_entry.html
Start by defining the sets and parameters of your problem, supposing you have 100 vertices, you can declare x like this for example:
Set x /x1*x100/;
alias(x,x2);
Because you will need to use the same set twice in your matrix, you have to define an alias so that x2 is interpreted by GAMS as the same as x in your model.
Then, declare n and b as parameters, you can do it like this:
Parameter
n /200/
c /100/;
Parameter b(x)
/
x1 3
x2 43
...
x100 23
/;
Note that parameters and variables with more than one value (i.e vectors or matrices) have to be defined over a previously defined set in GAMS. This is why b is defined over set x, think of x like indices of your vectors/matrices.
Declaration of A will have the form:
Variable A(x,x2);
Now you can define your equation using these sets, parameters and variables:
eq(x,x2) .. power(A(x,x2),n) * B(x2) =e= c;
Of course, you will still need to pick a suitable solver (NLP) and define an objective function, but this is how you would model the equation you want and variables for it.
I tried to solve the problem of a point belongs to the area. As a result, I need to get an answer: if a point belongs to the area or not.
Coordinates of the point entered by the user from the keyboard. When I try to transfer the coordinates of the point directly in a rule: belongsTo (1,1). I get the desired result (yes or no), but when I enter the coordinates with the keyboard
write ("Input X:"), readreal (X),
write ("Input Y:"), readreal (Y),
belongsTo (X, Y).
Then the answer will be 'no solutions' or just '2 solutions' (X = 0, Y = 0, X = 0, Y = 0, if you pass the point (0,0))
Here's the code completely:
PREDICATES
square(real,real)
semicircle(real,real)
belongsTo(real,real)
CLAUSES
square(X,Y):-
X>=-1,X<=0,
Y>=-1,Y<=0.
semicircle(X,Y):-
X>=0,Y>=0,
X*X+Y*Y<=1.
belongsTo(X,Y):-
square(X,Y);
semicircle(X,Y),!.
GOAL
write("Input X: "), readreal(X),
write("Input Y: "), readreal(Y),
belongsTo(X,Y).
As a result I need to get a solution like YES(if the point belongs to the area) or NO.
When you use the prompting method:
write("Input X:"), readreal(X),
write("Input Y:"), readreal(Y),
belongsTo(X, Y).
Prolog will display the values of X and Y along with the solution (yes or no) because these variables appear explicitly in your query. Any variables in your query it assumes you want to see the results of. If you just want to see yes or no, then you can make a predicate:
readuser :-
write("Input X:"), readreal(X),
write("Input Y:"), readreal(Y),
belongsTo(X, Y).
And then just query readuser. You'll then just get yes or no without the values of X and Y displayed.
As far as the different results, if you enter 0 and 0 for X and Y, this input will succeed twice: once for semicircle and once for square. Prolog faithfully finds both successful results.
When you are entering 1 and 1 and reading them as "real", I am suspecting that the internal representation is getting a little bit of floating point accuracy issue and internally becoming something like, 1.000000001 and these will fail both the semicircle and square tests.
As an aside, the semicircle is testing for the non-negative X and non-negative Y quadrant, not really a semicircle. Actual semicircle checks would be constraining just one of the coordinates in conjunction with X*X + Y*Y <= 1, e.g., X >= 0, X*X + Y*Y <= 1 would be the upper right and lower right quadrants of the semicircle.
I would like to know if there is a way to extract the X Value when I'm doing this :
aggregate_all(min(V), simulate(P, Color, V, X), Value)
The simulate predicate is used with P and Color as inputs and V and X as outputs.
For now, this works well to get the min value of V, but what I actually want is to get the value of X when V is at its minimum.
Is there a way to do that ? Any idea about how should I proceed ?
aggregate library supports a 'Witness' on min/max scalar aggregates: then this should work
aggregate_all(min(V,X), simulate(P, Color, V, X), min(Value,X))
Currently I use a single equation with different combination of known/unknown parameters. As I don't have any fancy calculator it would be much easier to define the equation in Mathematica and passing known parameters to calculate unknown values.
I would be very thankful if anyone of you could give an example solution (if possible using given equation).
Let's say we have an equation of satellite speed at given point in the elliptical orbit:
v = sqrt(u(2/r - 1/a))
where
v = speed
u = constant 3.986 * 10^14 m^3/s^2
r = radius (distance from the center of the Earth)
a = semi major axis of the ellipse
This equation can be used to calculate the speed or for example we know what is the speed needed for a manoeuvre to move the cargo to other orbit and have to model the orbit (a) at given radius (r)
Thanks!
You can define equations in Mathematica using the ":=" operator. To define the example equation:
v[u_, r_, a_] := Sqrt[u*(2/r-1/a)]
I'm not sure how to generalize it to solve for any unknown...If I figure it out I'll get back to you.
You may want to try something like:
Solve[v[1, r, 7]==15, r]
that will solve for r assuming you know v, u, and a... you can then change each of the paramaters for the unknown...
A little bit late :) ... but Reduce[] does what you want. We define a function:
solveForMe[rules_] := Reduce[( v == Sqrt[3.986*10^14 *(2/r - 1/a)]) /. rules];
and invoke it with any valid combination for the assignments. For example:
In[72]:= Off[Reduce::ratnz];
solveForMe[{a -> 7 10^6, r -> 7 10^6}]
solveForMe[{v -> 10, r -> 7 10^6}]
solveForMe[{v -> 10, a -> 7 10^6}]
The output is :
Out[73]= v == 7546.05
Out[74]= a == 3.5*10^6
Out[75]= r == 1.4*10^7
HTH! ...