3

How can I solve this system for positive values of x? I used fval but it can't find the answer and asks for larger iterations which is unhelpful...
a must be positive and smaller than 0.05
b must be larger than 88

function F = Final_Project_2(x)
 F = [(1/x(1)) + (1/x(2))- (2/(7*x(3)));
       (x(3)+2*x(4))*(15*x(2))/((x(1)+x(2))*x(3)-0.7/x(3))-14;
       (x(3)*((0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)))/(x(3)+(0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)) - a;
       ((0.576*x(2)*x(3)/(x(1)+x(2))*x(3)) - 0.27*x(4)/x(3))-b];

Edit: How this question is "too localized"?!!
I derived this system of equations from designing a Common Emitter Amplifier. First equation is came from independency from $/betha /$. Second one is kvl from Collector to Emitter. Third one is the CE gain.Last one is R_in

11
  • 4
    Completely unclear statement. What are you trying to solve for? The vector x, or a and b? Even with that, there is no presumption that a solution MUST exist.
    – user85109
    Commented Dec 19, 2012 at 9:49
  • Anyway, how is this question different from your first question, on exactly the same thing?
    – user85109
    Commented Dec 19, 2012 at 10:41
  • @woodchips not that unclear... Perhaps not well phrased but its a typical problem in optimization. The poster's last question was a syntax question - this is a question on how to solve the system. I disagree with the closing as this type of problem is hit by many engineers with real world design problems.
    – ccook
    Commented Dec 19, 2012 at 13:46
  • Is it unclear? I just want to solve for positive values of x. Also some constants in equations may be arbitrary chosen. I can't understand why should this question should be closed?! My first question may look similar to this one but it is more complicated because of the constraints in it Commented Dec 19, 2012 at 15:38
  • @ccook - unclear because no place in the statement do we learn that x is to be solved for, or is it a and b? After all, it appears that constraints were placed on a and b.
    – user85109
    Commented Dec 19, 2012 at 22:26

1 Answer 1

6

This would fit well under the non linear constrained optimization category, fmincon is helpful here. Fmincon allows you to solve the non linear system while placing upper and lower bounds on the solution vector. The problem is that the solution will depend on your starting point... So if you have a good guess for where the solution should be that helps GREATLY.

The analogy is like asking the solver to climb to the top of the mountain in front of it, or asking it to find the tallest peak in Europe by backpacking from some random starting point. When you are close you can just walk 'up'.

Anyway, here's how you can do this.

function test()

    a = .05
    b = 88


    xo = [100 100 100 100 a b]


    options = optimset('MaxFunEvals',1E5, ...
        'MaxIter', 1E5, ...
        'TolFun', 1E-32, ...
        'TolX', 1E-32, ...
        'TolCon', 1E-32);

    x = fmincon(@(X) Ftest(X), xo, [], [], [], [], ...
        [-inf -inf -inf -inf a b], [], [],  options)

    Final_Project_2(x)

    function F = Ftest(x)
        F = norm(Final_Project_2(x))
    end

    function F = Final_Project_2(x)
        F = [(1/x(1)) + (1/x(2))- (2/(7*x(3)));
               (x(3)+2*x(4))*(15*x(2))/((x(1)+x(2))*x(3)-0.7/x(3))-14;
               (x(3)*((0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)))/(x(3)+(0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)) - x(5);
               ((0.576*x(2)*x(3)/(x(1)+x(2))*x(3)) - 0.27*x(4)/x(3))-x(6)];
    end


end

x =

258.0438 84.3372 24.9576 34.8035 3.0926 88.0000

ans =

0.0043    -0.0000
0.0001    -0.0000

Note how the solver slammed against the lower bound on b. You can try playing with the initial guess and see if you can get it to find a nicer min. No solution is guaranteed...

This is the fun part, you can do better. Your system is not just a cost function but a constraint on x. Similar code, but using that information and you have a strong solution.

function test()

    a = .05
    b = 88


    xo = [100 100 100 100 a b]


    options = optimset('MaxFunEvals',1E4, ...
        'MaxIter', 1E4, ...
        'TolFun', 1E-32, ...
        'TolX', 1E-32, ...
        'TolCon', 1E-32);

    x = fmincon(@(X) Ftest(X), xo, [], [], [], [], ...
        [-inf -inf -inf -inf a b], [], @(X) xcon(X),  options)

    Final_Project_2(x)

    function F = Ftest(x)
        F = norm(Final_Project_2(x))
    end

    function [c,ceq] = xcon(x)
        c = []
        ceq = [(1/x(1)) + (1/x(2))- (2/(7*x(3)));
            (x(3)+2*x(4))*(15*x(2))/((x(1)+x(2))*x(3)-0.7/x(3))-14;
            (x(3)*((0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)))/(x(3)+(0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)) - x(5);
           ((0.576*x(2)*x(3)/(x(1)+x(2))*x(3)) - 0.27*x(4)/x(3))-x(6);
           (x(3)*((0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)))/(x(3)+(0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)) - x(5);
            ((0.576*x(2)*x(3)/(x(1)+x(2))*x(3)) - 0.27*x(4)/x(3))-x(6)];
    end

    function F = Final_Project_2(x)
        F = [(1/x(1)) + (1/x(2))- (2/(7*x(3)));
               (x(3)+2*x(4))*(15*x(2))/((x(1)+x(2))*x(3)-0.7/x(3))-14;
               (x(3)*((0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)))/(x(3)+(0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)) - x(5);
               ((0.576*x(2)*x(3)/(x(1)+x(2))*x(3)) - 0.27*x(4)/x(3))-x(6)];
    end


end

x =

360.8859 132.2940 27.6590 34.2885 3.6943 117.8688

ans =

1.0e-14 *

-0.0002 0.1776 -0.0444 0

Think of the second method as giving the backpacker a set of trails/roads to use. It guides the solver through the R^6 space.

2
  • You could also help the solver by moving some of the equations into the non linear constraints arguement. It should help the solver. For example, x(1) is constrained by x(2) and x(3). A constraint is better than acost function.
    – ccook
    Commented Dec 19, 2012 at 12:05
  • I went ahead and added the suggestion to the solution.
    – ccook
    Commented Dec 19, 2012 at 12:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.