Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Inline func. & fsolve

Subject: Inline func. & fsolve

From: Baha Kuzu

Date: 2 Apr, 2011 08:08:05

Message: 1 of 6

I am trying to solve this problem below. If anybody can help figure out the problem I appreciate.

I am trying to solve k:
______________________
>function x = extIIinv ( P, mu, sigma ) %P,mu,sigma are evaluated in main program.
  Vx = sigma / mu;
  k = 2.0 + 0.90*Vx^-1.1; % initial guess for k for fsolve
  k = fsolve(inline('Vx - sqrt(gamma(1-2/k)/(gamma (1-1/k))^2 - 1)','k'),k);
_______________________
Let's say P = 0.1:0.1:0.9, mu=0.9, sigma=0.7
This does not work as it is here. It says "Undefined function or variable 'Vx' I does not recognize Vx=sigma/mu value just above of it.
But if I plug sigma/mu=0.7/0.9=0.7778, it works. I could not figure out why it does not take the value from "Vx=sigma/mu."
Any suggestions please?

Subject: Inline func. & fsolve

From: Bruno Luong

Date: 2 Apr, 2011 10:18:04

Message: 2 of 6

"Baha Kuzu" <ibaha411@hotmail.com> wrote in message <in6lh5$f4p$1@fred.mathworks.com>...

> Any suggestions please?

Yes, drop using INLINE, use regular function and anonymous function.

Bruno

Subject: Inline func. & fsolve

From: Baha Kuzu

Date: 2 Apr, 2011 15:22:04

Message: 3 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <in6t4s$7u6$1@fred.mathworks.com>...
> "Baha Kuzu" <ibaha411@hotmail.com> wrote in message <in6lh5$f4p$1@fred.mathworks.com>...
>
> > Any suggestions please?
>
> Yes, drop using INLINE, use regular function and anonymous function.
>
> Bruno

thank you for your reply Bruno,
If I drop using inline, there is still a problem about defining the function. This did not help me to solve it.

Subject: Inline func. & fsolve

From: Baha Kuzu

Date: 2 Apr, 2011 19:26:04

Message: 4 of 6

Thank you again Bruno,
Here by using regular function and anonymous function;

 function x = extIIinv ( P, mu, sigma ) %P,mu,sigma are evaluated in main program
 Vx = sigma / mu; % coefficient of variation
 fun =@(k)(Vx - sqrt(gamma(1-2/k)/(gamma (1-1/k))^2 - 1));
 k = 2.0 + 0.90*Vx^-1.1; % initial guess for k
 k = fsolve(fun, k);
_________________
This gives me a result, I suppose this is correct. But I get this warning on command window which I am not sure its meaning. Could anybody explain what this warning mean? Is it normal warning when you use fsolve? (this is first time I use fsolve)
I appreciate,
__
Baha

Warning is below:
_________________
Equation solved.

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

<stopping criteria details>
Equation solved. The sum of squared function values, r = 5.254763e-016, is less than
sqrt(options.TolFun) = 1.000000e-003. The relative norm of the gradient of r, 2.006069e-008,
is less than options.TolFun = 1.000000e-006.

Optimization Metric Options
relative norm(grad r) = 2.01e-008 TolFun = 1e-006 (default)
r = 5.25e-016 sqrt(TolFun) = 1.0e-003 (default)

Subject: Inline func. & fsolve

From: Steven_Lord

Date: 4 Apr, 2011 02:25:37

Message: 5 of 6



"Baha Kuzu" <ibaha411@hotmail.com> wrote in message
news:in7t8c$3hs$1@fred.mathworks.com...
> Thank you again Bruno,
> Here by using regular function and anonymous function;
>
> function x = extIIinv ( P, mu, sigma ) %P,mu,sigma are evaluated in main
> program Vx = sigma / mu; % coefficient of variation
> fun =@(k)(Vx - sqrt(gamma(1-2/k)/(gamma (1-1/k))^2 - 1));
> k = 2.0 + 0.90*Vx^-1.1; % initial guess for k
> k = fsolve(fun, k);
> _________________
> This gives me a result, I suppose this is correct. But I get this warning
> on command window which I am not sure its meaning. Could anybody explain
> what this warning mean? Is it normal warning when you use fsolve? (this is
> first time I use fsolve)
> I appreciate,
> __
> Baha
>
> Warning is below:
> _________________
> Equation solved.
>
> fsolve completed because the vector of function values is near zero
> as measured by the default value of the function tolerance, and
> the problem appears regular as measured by the gradient.

This does NOT use the words "Error" or "Warning", and therefore is NOT an
error or a warning. It is simply a status message. If you don't like it, use
OPTIMSET to create an options structure with the Display option set to 'off'
and pass that options structure as the appropriate input in your call to
FSOLVE.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Inline func. & fsolve

From: Baha Kuzu

Date: 4 Apr, 2011 15:55:05

Message: 6 of 6

> This does NOT use the words "Error" or "Warning", and therefore is NOT an
> error or a warning. It is simply a status message. If you don't like it, use
> OPTIMSET to create an options structure with the Display option set to 'off'
> and pass that options structure as the appropriate input in your call to
> FSOLVE.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Thank you Steve,this is what I was expecting to hear.
Sincerely,
__
Baha

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us