# Matlab

```Experiment No. 01
Name of the Experiment: fminunc-Unconstrained Nonlinear and Linear
programming Minimization in MATLAB
fminunc-Unconstrained Nonlinear Minimization:
Equation: 5*x(1)^2+2*x(2)^2+4*x(1)*x(2)+3*x(2)+1
function f = objfunc(x)
f=(5*x(1)^2+2*x(2)^2+4*x(1)*x(2)+3*x(2)+1);
options=optimoptions(@fminunc,'Algorithm','quasi-newton');
x0=[-1,1];
[x,fval,exitflag,output]=fminunc(@objfunc,x0,options);
Local minimum found.
Optimization completed because the size of the gradient is less than
the default value of the optimality tolerance.
<stopping criteria details>
>> output
output =
iterations: 5
funcCount: 18
stepsize: 1.6241e-05
lssteplength: 1
firstorderopt: 5.9605e-08
algorithm: 'quasi-newton'
message: 'Local minimum found.…'
>> x
x=
0.5000 -1.2500
1
>> fval
fval =
-0.8750
>> exitflag
exitflag =
1
Another Way:
Optimization Tool:
Figure 1.1: Solving Using Optimization Tool
2
Figure 1.2: Current Step
Linear Programming:
Equation:
𝑀𝑎𝑥, 𝑧 = 4𝑥1 + 5𝑥2 + 𝑥3
𝑥1 + 3𝑥2 + 𝑥3 ≤ 50
3𝑥1 + 2𝑥2 + 4𝑥3 ≤ 60
3𝑥1 + 4𝑥2 ≤ 20
3
f = [-4 -5 -1]
f=
-4
-5
-1
>> A=[1 3 1;3 2 4;3 4 0]
A=
1
3
1
3
2
4
3
4
0
>> b=[50;60;20]
b=
50
60
20
>> Aeq=[]
Aeq =
[]
>> beq=[]
beq =
[]
>> lb=[0 0 0]
lb =
0
0
0
>> ub=[]
ub =
[]
>> [x z]=linprog(f,A,b,Aeq,beq,lb,ub)
Optimization terminated.
x=
0.0000
4
5.0000
12.5000
z=
-37.5000
>> z=z*-1
z=
37.5000
5
```