0

I have written this function, and I have already defined values for rg and Lp, but still when I run this function it returns the error : (Input argument "Lr" is undefined.

Error in ==> Bis at 12 if f(Lr,rg,Xo)*f(Lr,rg,Xf)>0)

here is the function :

function[Lp,Xo,Xf]=Bis(Lr,rg)

Xo=0;
Xf=10;
Err=0.01;

syms x;
f=inline('(sqrt((2/3)*(((x*Lr)/3)-(x*x)+((2*x*x*x)/Lr)-((2*x*x*x*x)/(Lr*Lr))+(((2*x*x*x*x)/(Lr*Lr))*exp(-Lr/x))))-rg)');


    if f(Lr,rg,Xo)*f(Lr,rg,Xf)>0
        disp('The values you entered are not apropriate !')
        PlotLpFunction;
    Lp='unknown';
    elseif f(Lr,rg,Xo)*f(Lr,rg,Xf)==0
        if f(Lr,rg,Xo)==0
            Lp=Xo;
        elseif f(Lr,rg,Xf)==0
            Lp=Xf;
        end

    elseif f(Lr,rg,Xo)*f(Lr,rg,Xf)<0
        xi=(Xf-Xo)/2;
        while abs(f(Lr,rg,xi))>Err 
            if f(Lr,rg,xi)*f(Lr,rg,Xf)<0
                Xo=xi;
                xi=(Xo+Xf)/2;
            elseif f(Lr,rg,xi)*f(Lr,rg,Xf)>0
                Xf=xi;
                xi=(Xo+Xf)/2;   
            end
        end
        Lp=xi;
    end
1
  • 1
    Can you show us how you call this function? Commented Aug 23, 2012 at 14:41

1 Answer 1

2

The code executes for me on the newest version of Matlab, other than the fact that I don't have the PlotLpFunction.

My initial impression was that you forgot to send the Lr (and all other argument) into you're inlined f function, very easy to fix by adding them as arguments to the inline function. You'll find the full usage in the official documentation.

The relevant part being

inline(expr,arg1,arg2,...) constructs an inline function whose input arguments are specified by the strings arg1, arg2,.... Multicharacter symbol names may be used.

but it seems to form the inline just fine by itself on both Matlab 2011b and 2008b, from context presumably. Answer is accepted now, so presumably that was the problem. Can anyone else reproduce his problem? If so please provide your Matlab version or other circumstances.

Sign up to request clarification or add additional context in comments.

9 Comments

I read that .. and what I have done is that I just inserted Lr,rg in the end of my inline sentance like this f=inline('(sqrt((2/3)*(((xLr)/3)-(xx)+((2*xxx)/Lr)-((2*xxxx)/(LrLr))+(((2*xxxx)/(LrLr))*exp(-Lr/x))))-rg)',Lr,rg);
I got the error : Input argument "Lr" is undefined. Error in ==> Bis at 9 f=inline('(sqrt((2/3)*(((xLr)/3)-(xx)+((2*xxx)/Lr)-((2*xxxx)/(LrLr))+(((2*xxxx)/(LrLr))*exp(-Lr/x))))-rg)',Lr,rg); >>
It wants the variable names as strings, so pass in 'Lr', 'rg', and 'x'
I don't think that's the problem here. >> f=inline('(sqrt((2/3)*(((xLr)/3)-(xx)+((2*xxx)/Lr)-((2*xxxx)/(LrLr))+(((‌​2*xxxx)/(LrLr))*exp(-Lr/x))))-rg)') f = Inline function: f(Lr,rg,x) = (sqrt((2/3)*(((xLr)/3)-(xx)+((2*xxx)/Lr)-((2*xxxx)/(LrLr))+(((2*xxxx)/(LrLr))*exp(-Lr/x))))-rg)
Alright my original answer was definitely wrong. Still can't reproduce your error but your code also doesn't make any sense: you've defined Xo as 0 which makes the first part of your expression sym computed expression evaluate to NaN.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.