Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Q. Develop a program to bracket the minimum of a one dimensional function.

The user can be expected to provide a function which calculates the one dimensional function, and also a starting point, and any other parameters specified by the creator of the program.

Solution: As a minimum is bracketed by three points a, b, c, if: 1) b is between a and c 2) f(b) < f(a) and f(b) < f(c) In this situation, provided the function is continuous, there is guaranteed to be a local minimum in between a and c. As it is a simple case of finding the minimum, we will first define a delta with which the query will increase in order to find the a and c in between which the minima lies. We will then define two more points using delta and initial point and find the function values at each point. If the function is continuously going up or continuously going down or have a maxima between x3 and x1 the loop will be executed to find next x1,x2,x3 . When a minima is found the programme will break and the result displayed.\ Code (Scilab): Function file:

function z=func(x) z= // user defined function to be put in here endfunction


Execution file: clc; clear; getf func.sci; ini=input("Please enter the value for initial point "); // ini represents the starting point user wants to give del=input("Please enter the value for delta "); // del represents the interval by which sampling has to be done to bracket the minima x1=ini; x2=x1+del; // second point x3=x2+del; // third point while (func(x1)>func(x2)) & (func(x2)>func(x3)) | (func(x1)<func(x2)) & (func(x2)<func(x3)) | ((func(x1)<func(x2)) & (func(x2)>func(x3)); // the above condition represents the case where either the function is continuously going up or continuously going down or have a maxima between x3 and x1 x1=x2; x2=x3; x3=x2+del; else s1=x1;

s2=x3; end printf ('The bracket lies between %f and %f',s1,s2) The program will provide us with the first minima that it encounters Shortcomings: I was not able to come up with a coding system to break the operation to avoid infinite loop in case no minima lies ahead of the starting point. Even using counters it will display the final values as the brackets instead of displaying an error message. It is assumed that only one point will be provided.

-Submitted by

Umang Kumar Rathi SC07b097 Sem 6, B.Tech Aerospace

You might also like