In [2]:
x = 10
Out[2]:
In [4]:
x + 1
Out[4]:
In [5]:
else = false
In [6]:
function f(x, y)
x + y
end
Out[6]:
In [8]:
f(1,2)
Out[8]:
In [9]:
∑(x,y) = x + y
Out[9]:
In [10]:
∑(2, 3)
Out[10]:
In [11]:
function g(x,y)
return x * y
x + y
end
Out[11]:
In [12]:
f(x,y) = x + y
Out[12]:
In [13]:
f(2,3)
Out[13]:
In [14]:
g(2,3)
Out[14]:
In [15]:
1 + 2 + 3
Out[15]:
In [16]:
+(1,2,3)
Out[16]:
In [17]:
x -> x^2 + 2x - 1
Out[17]:
In [18]:
function (x)
x^2 + 2x - 1
end
Out[18]:
In [19]:
P = download("https://raw.githubusercontent.com/nassarhuda/easy_data/master/programming_languages.csv","programminglanguages.csv")
Out[19]:
In [20]:
;ls
In [28]:
using DelimitedFiles
P,H = readdlm("programminglanguages.csv",header=true)
Out[28]:
In [38]:
using Pkg
Pkg.add("Clp")
Pkg.add("Cbc")
Pkg.add("GLPK")
In [40]:
using JuMP, GLPK
# 모델 생성
m = Model(with_optimizer(GLPK.Optimizer))
# Variable 선언
@variable(m, 0<= x1 <=10)
@variable(m, x2 >=0)
@variable(m, x3 >=0)
# 목적 함수
@objective(m, Max, x1 + 2x2 + 5x3)
# 제약 조건 설정
@constraint(m, constraint1, -x1 + x2 + 3x3 <= -5)
@constraint(m, constraint2, x1 + 3x2 - 7x3 <= 10)
# Optimization Model 출력
print(m)
In [41]:
# 최적화 문제 풀기
JuMP.optimize!(m)
# Optimal Solution Print
println("Optimal Solutions:")
println("x1 = ", JuMP.value(x1))
println("x2 = ", JuMP.value(x2))
println("x3 = ", JuMP.value(x3))
# Optimal dual variables Print
println("Dual Variables:")
println("dual1 = ", JuMP.shadow_price(constraint1))
println("dual2 = ", JuMP.shadow_price(constraint2))
In [42]:
@variable(m, x[1:3] >= 0)
Out[42]:
In [43]:
c = [1; 2; 5]
@objective(m, Max, sum( c[i]*x[i] for i in 1:3))
Out[43]:
In [45]:
A = [-1 1 3;
1 3 -7]
b = [-5; 10]
@constraint(m, constraint3, sum( A[1,i]*x[i] for i in 1:3) <= b[1] )
@constraint(m, constraint4, sum( A[2,i]*x[i] for i in 1:3) <= b[2] )
Out[45]:
In [46]:
using Pkg
Pkg.add("PyPlot")
In [48]:
using PyPlot
# Preparing a figure object
fig = figure()
# Data
x = range(0, stop=2*pi, length=1000)
y = sin.(3*x)
# Plotting with linewidth and linestyle specified
plot(x, y, color="blue", linewidth=2.0, linestyle="--")
# Labeling the axes
xlabel(L"value of $x$")
ylabel(L"\sin(3x)")
# Title
title("Test plotting")
# Save the figure as PNG and PDF
savefig("plot1.png")
savefig("plot1.pdf")
# Close the figure object
close(fig)
In [ ]: