Thread Subject: ??? Undefined function or variable 'N'.

Subject: ??? Undefined function or variable 'N'.

From: Reza Gh

Date: 3 Jan, 2008 12:55:45

Message: 1 of 10

Hello all,
I keep getting "??? Undefined function or variable 'N'."
when I try to use any optimization technique for following
function.
I guess there is something wrong with my function
declaration. Any help is highly appreciated.

function [fx]=myfun(D,N,d)
fx = (10^4) * (N+2) * D * d^2 ;


d = 0.001:0.1:2.00

N = 2.000:1:15.000

D = 0.025:0.1:1.500


Subject: ??? Undefined function or variable 'N'.

From: John D'Errico

Date: 3 Jan, 2008 13:11:56

Message: 2 of 10

"Reza Gh" <reza-ghaf@hotmail.co.uk> wrote in message
<flim0h$om0$1@fred.mathworks.com>...
> Hello all,
> I keep getting "??? Undefined function or variable 'N'."
> when I try to use any optimization technique for following
> function.
> I guess there is something wrong with my function
> declaration. Any help is highly appreciated.
>
> function [fx]=myfun(D,N,d)
> fx = (10^4) * (N+2) * D * d^2 ;
>
>
> d = 0.001:0.1:2.00
>
> N = 2.000:1:15.000
>
> D = 0.025:0.1:1.500

Your problem is not that of function definition,
but in problem definition, and understanding
how the optimization tools work. You cannot
just optimize a bunch of numbers.

What are you optimizing? For fixed vectors
d, N, and D, this function returns a fixed set
of results, a vector. What is the independent
variable in your optimization? What is the
response that you will minimize, or maximize,
or find a root for?

HTH,
John


Subject: Input argument "N" is undefined.

From: Reza Gh

Date: 3 Jan, 2008 13:12:12

Message: 3 of 10

CORRECTION CORRECTION

Hello all,
I keep getting "??? Input argument "N" is undefined."
when I try to use any optimization technique for following
function.
I guess there is something wrong with my function
declaration. Any help is highly appreciated.

function [fx]=myfun(D,N,d)
fx = (10^4) * (N+2) * D * d^2 ;


d = 0.001:0.1:2.00

N = 2.000:1:15.000

D = 0.025:0.1:1.500

Subject: Input argument

From: John D'Errico

Date: 3 Jan, 2008 13:18:41

Message: 4 of 10

"Reza Gh" <reza-ghaf@hotmail.co.uk> wrote in message
<flimvc$neh$1@fred.mathworks.com>...
> CORRECTION CORRECTION

You have not answered my questions.

John

Subject: ??? Undefined function or variable 'N'.

From: Reza Gh

Date: 3 Jan, 2008 13:24:11

Message: 5 of 10

Thanks John for your reply.

I am trying to minimize weight of :
f(x) = 10^4 (N+2)D d^2
subject to constrains:
g1(x) = 1 - (D^3 N / (71785 d^4)) <= 0
g2(x) = ((4D^2 - d D)/(12566( D d^3 - d^4))) + (1 / (5108
d^2)) - 1 <= 0
g3(x) = 1 - ((140.45 d) / (D^2 N)) <= 0
g4(x) = ((D + d) / 1.5) - 1 <= 0

Thanks again for your time,
 

Subject: ??? Undefined function or variable 'N'.

From: John D'Errico

Date: 3 Jan, 2008 13:31:10

Message: 6 of 10

"Reza Gh" <reza-ghaf@hotmail.co.uk> wrote in message
<flinlr$j5i$1@fred.mathworks.com>...
> Thanks John for your reply.
>
> I am trying to minimize weight of :
> f(x) = 10^4 (N+2)D d^2
> subject to constrains:
> g1(x) = 1 - (D^3 N / (71785 d^4)) <= 0
> g2(x) = ((4D^2 - d D)/(12566( D d^3 - d^4))) + (1 / (5108
> d^2)) - 1 <= 0
> g3(x) = 1 - ((140.45 d) / (D^2 N)) <= 0
> g4(x) = ((D + d) / 1.5) - 1 <= 0
>
> Thanks again for your time,

Ok. Then there are three variables. You need
to define your function as a function of ONE
input vector, of length 3.

fun = @(X) 10^4*(X(1)+2)*X(2)*X(3)^2

Likewise, define your constraints in the
save way. You will probably want to use
fmincon.

John

Subject: ??? Undefined function or variable 'N'.

From: Reza Gh

Date: 3 Jan, 2008 13:46:05

Message: 7 of 10

Cheers John.

This might sound a bit novice but I have got couple of
Questions:

1- How can I declare N,d and D in the function (fun = @(X)
10^4*(X(1)+2)*X(2)*X(3)^2)?
2- I want to use generic algorithm, Tabu search or
simulated annealing to optimize this function, have you got
any suggestion how to implement that in MatLab?

Regards,

Subject: ??? Undefined function or variable 'N'.

From: John D'Errico

Date: 3 Jan, 2008 14:14:51

Message: 8 of 10

"Reza Gh" <reza-ghaf@hotmail.co.uk> wrote in message
<fliout$avb$1@fred.mathworks.com>...
> Cheers John.
>
> This might sound a bit novice but I have got couple of
> Questions:
>
> 1- How can I declare N,d and D in the function (fun = @(X)
> 10^4*(X(1)+2)*X(2)*X(3)^2)?

What do you mean by "declaring" these variables?

X(1) takes on the same purpose as N.
X(2) takes on the same purpose as D.
X(3) takes on the same purpose as d.

The vector X specifies these three variables.


> 2- I want to use generic algorithm, Tabu search or
> simulated annealing to optimize this function, have you got
> any suggestion how to implement that in MatLab?

You will need to write these codes. I think that
you might find a simulated annealing code on
the file exchange, but I doubt that it handles
constraints, and I'm not sure of the quality of
the code.

John

Subject: ??? Undefined function or variable 'N'.

From: Charles Cuell

Date: 3 Jan, 2008 15:49:47

Message: 9 of 10

"Reza Gh" <reza-ghaf@hotmail.co.uk> wrote in message
<flinlr$j5i$1@fred.mathworks.com>...
> Thanks John for your reply.
>
> I am trying to minimize weight of :
> f(x) = 10^4 (N+2)D d^2
> subject to constrains:
> g1(x) = 1 - (D^3 N / (71785 d^4)) <= 0
> g2(x) = ((4D^2 - d D)/(12566( D d^3 - d^4))) + (1 / (5108
> d^2)) - 1 <= 0
> g3(x) = 1 - ((140.45 d) / (D^2 N)) <= 0
> g4(x) = ((D + d) / 1.5) - 1 <= 0
>
> Thanks again for your time,
>

Hi, Reza.

I think you have some issues with the way the problem is
set up. For instance, seeking local minima in the interior
of the constraint set requires solving df = 0.
Necessarily, D = 0 or d = 0, for which a number of the
constraints are undefined.

Rewriting the constraints should help clear up this
problem, though g2 will be a little tricky.

The objective function, f, and all the constraints are easy
enough to differentiate by hand, so that a straight forward
search for numbers D, d, and N that satisfy df = 0 and that
lie in the interior of the contraints is easily possible.

For the boundary of the constraint set, you would use
Lagrange multipliers. You may need to use a numeric method
to find solutions, but you should be able to at least
obtain some solutions by hand or even determine how many
solutions there are before going to a numeric method.

Any multivariable calculus text will have details and
examples of how to solve a problem like this.

Good luck.

Charles

Subject: ??? Undefined function or variable 'N'.

From: Hailey Yang

Date: 10 Jul, 2008 19:01:03

Message: 10 of 10

Hi, John

Thanks for the reply. I kind of have the same question as
Rena: how can we declare all three variables as one X? What
if they are matrixes that have different dimensions?

Yingxia

"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <fliqkr$arc$1@fred.mathworks.com>...
> "Reza Gh" <reza-ghaf@hotmail.co.uk> wrote in message
> <fliout$avb$1@fred.mathworks.com>...
> > Cheers John.
> >
> > This might sound a bit novice but I have got couple of
> > Questions:
> >
> > 1- How can I declare N,d and D in the function (fun = @
(X)
> > 10^4*(X(1)+2)*X(2)*X(3)^2)?
>
> What do you mean by "declaring" these variables?
>
> X(1) takes on the same purpose as N.
> X(2) takes on the same purpose as D.
> X(3) takes on the same purpose as d.
>
> The vector X specifies these three variables.
>
>
> > 2- I want to use generic algorithm, Tabu search or
> > simulated annealing to optimize this function, have you
got
> > any suggestion how to implement that in MatLab?
>
> You will need to write these codes. I think that
> you might find a simulated annealing code on
> the file exchange, but I doubt that it handles
> constraints, and I'm not sure of the quality of
> the code.
>
> John

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com