Scilab/C4/Optimization-Using-Karmarkar-Functions/English

From Script | Spoken-Tutorial
Jump to: navigation, search

Title of script: Optimization of Linear Functions with Linear Constraints Using Scilab

Author: Mukul R. Kulkarni

Keywords: Scilab, Optimization, karmarkar

Visual Cue Narration
Display Slide Welcome to the spoken tutorial on

'Optimization of Linear Functions with Linear Constraints Using Scilab'

Display Slide


Objectives

In this tutorial, We will learn
  • What is meant by Optimization?

And

  • How to use Scilab function karmarkar for optimization.


Display Slide


What is Optimization ?

Optimization means
  • Minimize or maximize a given objective function.
  • Which is also called as Cost function sometimes.
  • By varying the decision variables.
  • The decision variables are varied subject to the pre-defined constraints.


* These constraints are also in the form of some functions of the variables.
  • Optimization is extensively used in majority of the engineering as well as non-engineering fields like
    • Economics
    • Control Theory and
    • Operations & Research.


Display Slide


Scilab Function: karmarkar


The Scilab function Karmarkar is used for
  • Optimizing the linear objective function
  • subjected to linear constraints
  • on the decision variables

We will solve the following example using the karmarkar function:

Minimize

minus three 'x' one minus 'x' two minus three 'x' three

for

two 'x' one plus 'x' two plus 'x' three is less than or equal to two.

'x' one plus two 'x' two plus three 'x' three is less than or equal to five.

two 'x' one plus two 'x' two plus 'x' three is less than or equal to six.


where 'x' one 'x' two 'x' three are all greater than or equal to zero

Note that all the functions objective functions as well as constraints are linear



help Karmarkar


Enter


Scilab Function: karmarkar


Output Arguments

Before we solve the given problem go to scilab console and

type help karmarkar

and press Enter.

We can see the calling sequence of the argument.

The argument explaination, description and some examples in the help browser.

Close the help browser

We will summarize the input and output arguments here


Out put arguments are 'x' opt, 'f' opt, exitflag, iter,

'y' opt

  • 'x' opt : is the optimum solution .
  • 'f' opt : is the objective function value at optimum solution
  • 'exitflag' : is the status of execution, it helps in identifying if the algorithm is converging or not.
  • 'iter' : Is the number of iterations required to reach 'x' opt.
  • 'y' opt : is the structure containing the dual solution
    This gives the Lagrange multipliers.


Display Slide

Scilab Function: karmarkar


Input Arguments:


Input arguments are 'Aeq' 'beq' 'c' 'x' zero 'rtolf 'gam' 'maxiter' 'outfun' 'A' 'b' 'lb' and 'ub'


  • 'Aeq' : is the Matrix in the linear equality constraints.
  • 'beq' :is the right hand side of the linear equality constraints.
  • 'c' : is the Linear objective function co-efficients for 'x'.
  • 'x' zero : is the Initial guess .
  • 'rtolf' : is Relative tolerance on 'f' of 'x' equals to 'c' transpose multiplied by 'x'.
  • 'gam' : is the Scaling factor.
  • 'maxiter' : is the Maximum number of iterations after which the output is returned.
  • 'outfun' : is the additional user-defined output functions .
  • 'A' : is the Matrix of linear inequality constraints
  • 'b' : is the right hand sideof the linear inequality constraints.
  • 'lb' : is the lowerbound for 'x'.
  • 'ub' : is the Upper bounds for 'x'.


Display Slide


Using Scilab function karmarkar to solve an example

We can now solve the given example in Scilab using karmarkar function.

Go to the scilab console and type

Scilab Console


A = [2 1 1; 1 2 3; 2 2 1]

A =


2. 1. 1.

1. 2. 3.

2. 2. 1.


Enter


b = [2;5;6]

b =


2.

5.

6.


Enter


c = [-3; -1; -3]

c =


- 3.

- 1.

- 3.

Enter


lb = [0;0;0]

lb =


0.

0.

0.


Enter


clc


[xopt,fopt,exitflag,iter]=karmarkar([],[],c,[],[],[],[],[],A,b,lb)


Enter


Enter


xopt =


0.1999967

0.0000076

1.5999902


fopt =


- 5.3999683


iter =

70.


exitflag =


1.


'A' equals to open square bracket, two <space> one <space> one <semicolon> one <space> two <space> three <semicolon> two <space> two <space> one, close the square bracket.


And press Enter


similarly type,

'b' equals to open square bracket, two <semicolon>five <semicolon> six, close the square bracket.


And press Enter


'c' equals to open square bracket, minus three <semicolon> minus one <semicolon> minus three, close the square bracket.


And press Enter


Type

'lb' equals to open square bracket, zero <semicolon> zero <semicolon> zero, close the square bracket.


And press Enter


Now clear the Scilab console by clc command.


Type


open square bracket, 'x' opt <comma> 'f' opt <comma> 'exitflag' <comma> iter, close the square bracket equals to karmarkar open parenthesis, open square bracket, close the square bracket <comma> open square bracket, close the square bracket <comma> 'c' <comma> open square bracket, close the square bracket <comma> open square bracket, close the square bracket <comma> open square bracket, close the square bracket <comma> open square bracket, close the square bracket <comma> open square bracket, close the square bracket <comma> capital 'A' <comma> 'small b' <comma> 'lb', close the round bracket.


And Press enter


Press Enter to continue the Display


This will give the output as shown on the screen.


Where xopt is the optimal solution to the problem


fopt is the value of objective function calculated at optimum solution x is equal to xopt


and number of iteration required to reach optimum solution xopt is 70


Please note that: it is mandatory to specify the input arguments in same order.

In which they have been listed above, while calling the function

Display Slide

Summary

In this tutorial, we learned
  • What is Optimization?

And

  • Use of Scilab function karmarkar in optimization to solve linear problems.


Display Slide


Contact

To contact the scilab team, please write to contact@scilab.in
Disp1lay Slide


http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial

About the Spoken Tutorial Project

Watch the video available at the link shown below

It summarises the Spoken Tutorial project

If you do not have good bandwidth, you can download and watch it

Display Slide


Spoken Tutorial Workshops

The Spoken Tutorial Project Team

Conducts workshops using spoken tutorials

Gives certificates to those who pass an online test s

For more details, please write to

contact@spoken-tutorial.org

Display Slide


Acknowledgement

Spoken Tutorial Project is a part of the Talk to a Teacher project

It is supported by the National Mission on Education through ICT, MHRD, Government of India

More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro

Anuradha Amrutkar from IIT Bombay

Thank You for joining.

Contributors and Content Editors

Lavitha Pereira