Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab problems with fsolve

  1. Nov 20, 2011 #1
    Hi everyone,

    I am a matlab newbie and am having some problems getting fsolve to work. I tried using the example given in the help section but it keeps saying that my function (lambda_y1) since that is the first one it finds is unknown.

    My functions are generated like this (sorry for the messy notation):

    function F = myfun(lambda_y1,lambda_y2,h_1,h_2,F_c1,F_c2)

    F = [g_1+607200.*lambda_1.^3-1899000.*lambda_1.^2+1976400.*lambda_1-684600;




    F_c1.^2.*(4.*(h_m1-h_1).^2+(lambda_1.*y_01).^2)-16.*g_1^2.*(h_m1 - h_1).^2;

    F_c2.^2.*(4.*(h_m2+h_2).^2+(lambda_2.*y_02).^2)-16.*g_2^2.*(h_m2 + h_2).^2];

    I call it like this:
    f = fsolve(@myfun,x0,lambda_y1,lambda_y2,h_1,h_2,F_c1,F_c2);

    All the constants except for the unknowns are given earlier.

    Can anyone help me get this to run?

  2. jcsd
  3. Nov 21, 2011 #2
    What are the unknowns you are trying to find???
  4. Nov 21, 2011 #3
    First of all the syntax which you are using is not correct,
    most common and simple syntax is "f = fsolve(@fun,x0)", where x0 are the initial guesses.

    In your case also i guess x0 are the initial guesses, the correct syntax should be

    f = fsolve(@myfun,x0);

    Also, the myfun should like as follows:

    it should initialize all the unknowns with their initial guesses i.e.
    unknown1 = x0(1);
    unknown2 = x0(2);
    and so on,

    also you should define all the values of the constants inside the myfun itself.
    Constant1 = a;
    Constant2 = b; etc.

    I guess it will solve the problem.
  5. Nov 21, 2011 #4
    Hi again,

    Yep that did it, thanks alot, but now I have run into another problem. I run my equations and get the following stopping criteria:

    No solution found.

    fsolve stopped because the problem appears regular as measured by the gradient,
    but the vector of function values is not near zero as measured by the
    default value of the function tolerance.

    I get that there must be a problem with my equations, but I have no idea what to look for!

  6. Nov 21, 2011 #5
    As you think, may be there is some problem with your equations, then it will be better if you check them with some known values, see if it is giving correct result.
    (Also there may be the case that there is "no solution", which i think is not the case, if you are expecting some solution)
    Also it will be helpful if you simplify the equations.
    You will have to debug it...and see if there are any improvements.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook