simplex phase2


flamingo
01-20-2009, 10:47 AM
Update:

I am trying to use Simplex to solve an Ax = b problem. A is 100 x 10.
My code seems to set up the sparse columns and Aij as expected. I'd like to minimize the slack variables. How should I set up obj to do that? I've tried obj[1..n] = 1, obj[n..n+m] = 1, and obj[1..n+m] = 1. All seem to result in zero solution. (Only slack variables have non-zero values.) I'm reading the results from u.

Please advise if I'm either setting the objective function incorrectly or reading the solution from the wrong place.
thanks

kutta
02-01-2009, 08:12 AM
Hello Comarade
Did u try the codes in C++ for the subject item
If the same is valid
pl try the same below
#include <iostream>
#include <cmath>
using namespace std;

void maximum(double, double, double, double); // function prototype
double f(double); // function prototype

int main()
{
double delta; // step size
double a, b; // left and right ends of the original interval
double epsilon; // convergence criterion

// obtain the input data
cout << "Enter the limits of the original search interval, a and b: ";
cin >> a >> b;
cout << "Enter the convergence criteria: ";
cin >> epsilon;
cout << "Enter the step size: ";
cin >> delta;

maximum(a, b, epsilon, delta);

cin.get();cin.ignore(); // this line is optional

return 0;
}

void maximum(double a, double b, double epsilon, double delta)
{
double x1, x2;
double f1, f2;
double max;

// echo back the passed input data
cout << "\nThe original search interval is from " << a << " to " << b << endl;
cout << "The convergence criterion is: interval < " << epsilon << endl;
cout << "The step size is " << delta << endl;

x1 = a;
max = x1;
while(delta >= epsilon && max < b)
{
x2 = x1 + delta;
f1 = f(x1);
f2 = f(x2);
if (f1 < f2)
{
x1 = x2;
max = x2;
}
else
{
delta = delta / 2;
max = x1;
}
}

if(max > b && max != b)
max = max - delta;
cout << "\nThe max was found at x = " << max << endl;

return;
}

// function to evaluate f(x)
double f(double x)
{
const double PI = 2*asin(1.0); // value of pi

return (exp(-x) - sin(0.5 * PI * x));
}



However if the function is different pl alter and try
Thanks
As
Kutta
(C.R.Muthukumar)