Tackling variational problem with constraints - constraints

I need to minimize (preferably symbolically) functional
F = Integral(f(x)*cos(x)dx)
with constraints:
1)f(x) >= 0
2) Integral(f(x)dx) = 1
3) f(0) = 1
4) f'(x) <= 0
Is there any way to solve problem like this? Could this problem be solved in principle?
Thanks in advance

Related

/(::VariableRef,::QuadExpr) is not defined

I'm trying to solve a problem with JuMp and it's a non linear problem. So I have the error bellow :
/(::VariableRef,::QuadExpr) is not defined. Are you trying to build a nonlinear problem? Make sure you use #NLconstraint/#NLobjective.
And I'm using #NLobjective and #NLconstraint.
I have the problem at the second line of this function when I call it in my function bvpsolve:
function hamiltonien(z,eps)
u = z[:,8]./(2*eps*Cd2*z[:,6].*z[:,2])
h = z[:,5] .* z[:,1] .* [sin(z[i,4]) for i in size(z[:,4])] + z[:,6] .* (T(z[:,1])./z[:,3] - phi(z[:,1]) * S * z[:,2].^2 /(2*z[:,3])* (Cd1+Cd2*u^2) - g *sin(z[:,4])) - z[:,7] *Cs(z[:,2])*T(z[:,1]) + 1/eps * z[:,8] *(phi(z[:,1])*S*z[:,2] *u /(2*z[:,3]) - g/z[:,2] *cos(z[:,4]))
return 1
end
function bvpsolve(eps,N)
sys = Model(optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 5))
set_optimizer_attribute(sys,"tol",1e-8)
set_optimizer_attribute(sys,"constr_viol_tol",1e-6)
#variables(sys, begin
tf
x[1:N+1 , 1:n]
y[1:N+1 , 1:n]
0. ≤ h[1:N] ≤ 10
end)
Δt = (tf-t0)/N
# Objective
#NLobjective(sys, Min, sum(sum((x[i,j]-y[i,j])^2 for i in 1:N+1) for j in 1:n )/N + α*sum((h[i]-Δt)^2 for i in 1:N))
hx = hamiltonien(x,eps)
hy = hamiltonien(y,eps)
xpoint , ppointx = hvfun(hx,x)
ypoint , ppointy = hvfun(hy,y)
#NLconstraints(sys, begin
con_h0, x[1,1] - 3480. == 0
con_hf, x[N+1,1] - 9144. == 0
con_v0, x[1,2] - 151.67 == 0
con_vf, x[N+1,2] - 191. == 0
con_m0, x[1,3] - 69000. == 0
con_mf, x[N+1,3] - 68100. == 0
con_g0, x[1,4] - 69000. == 0
con_gf, x[N+1,4] - 68100. == 0
end)
...
end)
You can't construct nonlinear expressions outside the macros.
See the documentation: https://jump.dev/JuMP.jl/stable/manual/nlp/
You can use a user-defined function, but I don't understand your example. It hard-codes return 1, so I don't know what u and h are for.
Your example is also non-reproducible, because I don't know what hvfun is.
p.s., If you want to have a longer discussion, please post on the community forum: https://discourse.julialang.org/c/domain/opt/13. It's a bit easier to have a back-and-forward than on stack overflow.

How can I change the code so it can solve the model?

It is not possible for Julia to solve it when I use a[i, j] = 1. how can i get julia to solve this problem?
using JuMP
using GLPK
u = [1 2 3 ; 1 2 3 ; 1 2 3]
m = Model(GLPK.Optimizer)
#variable(m, a[1:3,1:3], Bin)
#objective(m, Max, sum(u[i,j]*a[i,j] for i=1:3, j=1:3))
#constraint(m, [a[i,j]=1], sum(a[i:j][i:j]) == 1)
solution = optimize!(m)
opt_value = value.(a)
in the line
#constraint(m, [a[i,j]=1], sum(a[i:j][i:j]) == 1)
1) You're trying to set a variable, not to test equality, instead use
a[i,j] == 1
2) i and j are undefined. Without a minimal example to run, I would say according to the previous line of your code, I would say something like
sum(<what-to-sum-here> for i=1:3, j=1:3)
Or loop on the list of index you want to use if not the proper one.

optimization (Maximization) in R

I have one function that wants to optimize (Maximize) in R, any one could help me.
My equation is as follow:
Y=-10.6134 -3.477*X1 +4.743*X2 +56.10*X3 -0.07671*X4 +0.1005*X1^2-0.0529*X2^2 -25.741*X3^2 +0.000279*X4^2 -0.0984*X1*X2 -1.351*X1*X3 -0.00407*X1*X4
With these limitations:
3 <= X1 <= 11
25 <= X2 <= 45
0.1 <= X3 <= 10
10 <= X4 <= 200
I already optimize that with “solver” function in “Excel” and also I try some packages such as “optim” and “nlminb” but they don’t work for me.
Please help me; I really need it for my university project.
Tnx
Define your function
f<-function(X1,X2,X3,X4){
-10.6134 -3.477*X1 +4.743*X2 +56.10*X3 -0.07671*X4 +
0.1005*X1^2-0.0529*X2^2 -25.741*X3^2 +0.000279*X4^2 -
0.0984*X1*X2 -1.351*X1*X3 -0.00407*X1*X4
}
Write your function as a one-argument function as this is needed for optim, and put a minus as your optimizing
f2 <- function(x) -f(x[1],x[2], x[3],x[4])
Use Optim
optim(par=c(6,35,5,100),fn=f2,lower = c(3,25,0.1,10),upper = c(11,45,10,200),method = "L-BFGS-B")

Not understanding the recurrence formula of n nodes with a height h in an AVL tree to show h <= 2 log n

I know the formula is: n(h) = n(h-1) + n(h-2) + 1
And I know it can be reduced as:
n(h) = n(h-1) + n(h-2) + 1
>= n(h-2) + n(h-2) + 1
>= 2n(h-2) + 1
>= 2n(h-2)
After this step I don't understand the recurrence that would come here. I was reading a proof online and they did this:
>= 2n(h-2)
>= 2(2n(h-4))
>= 2(2(2n(h-6)))
I'm not understanding that block. Why is each step multiplied by 2 and why is 2 more subtracted each time from the height? I'm having trouble visualizing it or something. Then the rest of the proof shows:
>=(2^i)n(h-2i)
I understand how they got that answer based on the pattern, and I can solve the rest of the proof, but I don't understand how that recursive pattern was chosen. I hope I'm making sense. If anyone can clarify this for me, I would appreciate it very much!
Given that n(h) >= 2n(h-2) for all h, we can apply this very same inequality for h-2 as well. This would give us:
n(h-2) >= 2n(h-2-2)
which is the same as
n(h-2) >= 2n(h-4).
If we now apply it again for h-4 (as we did for h-2) we get
n(h-4) >= 2n(h-4-2) = 2n(h-6).
Now we can replace these two last inequalities into the first one:
n(h) >= 2n(h-2) >= 2(2n(h-4)) >= 2(2(2n(h-6)))
and so on...

How to proceed with spoj LGIC?

I am trying to solve this problem http://www.spoj.pl/problems/LGIC/. I just can't figure out how is this sequence advancing.
By lagarange's it is too complex to solve for such a great range.
The farthest I could get was with factorials
1! = 1 & a1=2
2! = 2 & a2=4
3! = 6 & a3=11
4! = 24 & a4=36
5! = 120 & a5=147
6! = 720 & a6=778
Please guide me someone..
Perhaps the sequence is: An = n! + 2^n - n.
You can gat the Nth term using
T(n) = n! + pow(2,n) - n

Resources