Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Newbie optimization problem

Subject: Newbie optimization problem

From: Barry

Date: 16 Mar, 2008 03:46:42

Message: 1 of 12

Hello,

I am completely new to MatLab, and I have never actually
taken a class in linear algebra, either, so my question is
probably pretty elementary. I can't find any examples that
I recognize as analogous to my problem, though, so I thought
I would ask here.

I have a system of two matrix-vector equations. A is a
matrix with j rows and i columns, and B is A transposed.
Both logK and C are vectors with j rows, and logC is the
vector log10(C). logX and T are vectors with i rows. Here
are the equations:

A*logX + logK = logC

B*C = T

A, B, and logK are given, as are certain elements in the
logX and T vectors (but not others). The standard way of
solving this system is to rewrite the second equation as
B*C-T=Y, and optimize the non-fixed elements in logX and T
so that all the elements in Y are minimized.

I can actually do this just fine with the Solver in Excel by
telling it which cells to optimize, but of course it is
pretty slow. So anyway, can one of the solver functions in
MatLab handle this (I have the optimization toolbox,) and if
so, how do I set up the problem?

Thanks!

Barry

Subject: Re: Newbie optimization problem

From: D. Ismay

Date: 16 Mar, 2008 04:26:10

Message: 2 of 12

Barry wrote on 15-Mar-08 19:46 :
> Hello,
>
> I am completely new to MatLab, and I have never actually
> taken a class in linear algebra, either <snip>

Google:
Results 1 - 10 of about 407,000 for Linear Algebra and its applications. (0.20 seconds)

Help -- Matlab -- Getting Started

HTH, HAND

Subject: Re: Newbie optimization problem

From: Barry

Date: 16 Mar, 2008 05:47:04

Message: 3 of 12

"D. Ismay" wrote

> > I am completely new to MatLab, and I have never actually
> > taken a class in linear algebra, either <snip>
>
> Google:
> Results 1 - 10 of about 407,000 for Linear Algebra and its
applications. (0.20 seconds)
>
> Help -- Matlab -- Getting Started
>
> HTH, HAND

I'm sorry, I should have been more clear about my situation
for the sake of D. Umbass. I have spent hundreds of dollars
on MatLab and linear algebra books, and I have been reading
through all of them. I have not, however, found anything
that tells me how to optimize on particular elements of more
than one vector.

Maybe I just missed it. Maybe my grasp of linear algebra
isn't yet complete enough to see it when it's right in front
of me. And so I'm asking if anyone can tell me on which
MatLab optimization functions to focus my attention, or if I
would have to program some custom routine to do what I want.

Subject: Re: Newbie optimization problem

From: D. Ismay

Date: 16 Mar, 2008 17:00:33

Message: 4 of 12

Barry wrote on 15-Mar-08 21:47 :
> "D. Ismay" wrote
>
>>> I am completely new to MatLab, and I have never actually
>>> taken a class in linear algebra, either <snip>
>> Google:
>> Results 1 - 10 of about 407,000 for Linear Algebra and its
> applications. (0.20 seconds)
>> Help -- Matlab -- Getting Started
>>
>> HTH, HAND
>
> I'm sorry, I should have been more clear about my situation
> because I am a dumbass. <snip>

Edited, for the sake of TRUVTH! in usenet.

Subject: Re: Newbie optimization problem

From: Amir

Date: 16 Mar, 2008 18:05:04

Message: 5 of 12

"D. Ismay"
<nospam@WooHoo.WooHooHoo.WooHoo.WooHooHoo.HOOHOO.hoohoo.Woo
Hoo.WooHooHoo> wrote in message
<13tqkhhkb17re38@corp.supernews.com>...
> Barry wrote on 15-Mar-08 21:47 :
> > "D. Ismay" wrote
> >
> >>> I am completely new to MatLab, and I have never
actually
> >>> taken a class in linear algebra, either <snip>
> >> Google:
> >> Results 1 - 10 of about 407,000 for Linear Algebra
and its
> > applications. (0.20 seconds)
> >> Help -- Matlab -- Getting Started
> >>
> >> HTH, HAND
> >
> > I'm sorry, I should have been more clear about my
situation
> > because I am a dumbass. <snip>
>
> Edited, for the sake of TRUVTH! in usenet.
>

I honestly think Barry put good effort in describing his
problem, and it is a little harsh to direct him to google
search.

Anyway, from my understanding of your problem, I think you
need to write a matlab function to be optimized and
passing to it the unkonwn values (Note I did not pay
attnetion to dimensions, so this needs to be rewritten
with desired dimnsions ....etc):

function r=myfunc(T1, T2, T3, logX1, logX2, logX3)
T=[1 2 3 T1 T2 T3];
logX=[5 6 7 logX1 logX2 logX3];
logC=A*logX + logK;
C=exp(logC); % I am assuming your log is natural logrithm
r=B*C-T; %return result of this target function to be
minimized


Then use (pass) this function as an optimization target
function in one of Matlab's optimization routines, like:
fminunc
like this:
x0=[1 1 1 1 1 1]; %initial values for T1 T2 T3 logX1 logX2
logX3
x = fminunc(fun,x0)

(All optimization functions are similar in usage, so
knwing one will help you use the others).

Now you can proceed and read more in the help of this
function and general usage of optimization in Matlab.

-Amir

Subject: Re: Newbie optimization problem

From: Amir

Date: 16 Mar, 2008 18:07:03

Message: 6 of 12

"Amir " <amir_seyed@hotmail.com> wrote in message
<frjngg$3f5$1@fred.mathworks.com>...
> "D. Ismay"
>
<nospam@WooHoo.WooHooHoo.WooHoo.WooHooHoo.HOOHOO.hoohoo.Woo
> Hoo.WooHooHoo> wrote in message
> <13tqkhhkb17re38@corp.supernews.com>...
> > Barry wrote on 15-Mar-08 21:47 :
> > > "D. Ismay" wrote
> > >
> > >>> I am completely new to MatLab, and I have never
> actually
> > >>> taken a class in linear algebra, either <snip>
> > >> Google:
> > >> Results 1 - 10 of about 407,000 for Linear Algebra
> and its
> > > applications. (0.20 seconds)
> > >> Help -- Matlab -- Getting Started
> > >>
> > >> HTH, HAND
> > >
> > > I'm sorry, I should have been more clear about my
> situation
> > > because I am a dumbass. <snip>
> >
> > Edited, for the sake of TRUVTH! in usenet.
> >
>
> I honestly think Barry put good effort in describing his
> problem, and it is a little harsh to direct him to
google
> search.
>
> Anyway, from my understanding of your problem, I think
you
> need to write a matlab function to be optimized and
> passing to it the unkonwn values (Note I did not pay
> attnetion to dimensions, so this needs to be rewritten
> with desired dimnsions ....etc):
>
> function r=myfunc(T1, T2, T3, logX1, logX2, logX3)
> T=[1 2 3 T1 T2 T3];
> logX=[5 6 7 logX1 logX2 logX3];
> logC=A*logX + logK;
> C=exp(logC); % I am assuming your log is natural logrithm
> r=B*C-T; %return result of this target function to be
> minimized
>
>
> Then use (pass) this function as an optimization target
> function in one of Matlab's optimization routines, like:
> fminunc
> like this:
> x0=[1 1 1 1 1 1]; %initial values for T1 T2 T3 logX1
logX2
> logX3
> x = fminunc(fun,x0)
>
> (All optimization functions are similar in usage, so
> knwing one will help you use the others).
>
> Now you can proceed and read more in the help of this
> function and general usage of optimization in Matlab.
>
> -Amir
>

I meant:
x = fminunc(myfunc,x0)

Subject: Re: Newbie optimization problem

From: Barry

Date: 16 Mar, 2008 22:34:06

Message: 7 of 12

Thanks, Amir. The idea that you can minimize a function is
just what I think I was missing--I'll give it a try.

And thanks also for not dismissing my question. This is the
first time I have posted here, and it was kind of
discouraging to get my first reply from that other person.
I looked up his other posts, and there were many more of the
same kind. Must have a lot of time on his hands--I wonder why?

Barry

Subject: Re: Newbie optimization problem

From: D. Ismay

Date: 17 Mar, 2008 13:46:46

Message: 8 of 12

Amir wrote on 16-Mar-08 10:05 :
[...]
> I honestly think Barry put good effort in describing his
> problem, and it is a little harsh to direct him to google
> search.

The OP wrote, and I quote:

"I am completely new to MatLab, and I have never actually taken a class in linear algebra, either, so my question is probably pretty
elementary."

Given this, the reply was entirely reasonable. The self-described newbie's next-best choice was to whine about his circumstance in
a public newsgroup. Seems to me he got everything he wanted.

Subject: Re: Newbie optimization problem

From: Barry

Date: 17 Mar, 2008 16:59:08

Message: 9 of 12

"D. Ismay"

> The OP wrote, and I quote:
>
> "I am completely new to MatLab, and I have never actually
taken a class in linear algebra, either, so my question is
probably pretty
> elementary."
>
> Given this, the reply was entirely reasonable. The
self-described newbie's next-best choice was to whine about
his circumstance in
> a public newsgroup. Seems to me he got everything he wanted.

D., I only gave this preface to let people know where I am.
 I'm a beginner. That means that I may be missing something
that is obvious to more experienced people, and such
information might help other posters know how to frame their
answers.

But my question was not, "Can someone teach me linear
algebra?" or "How do you use MatLab?" Rather, it was a very
specific and straightforward question about how to perform
an optimization in a way that I had not seen described in
any documentation. And Amir was kind enough to give me a
very straightforward answer.

In other words, your reply was not reasonable, because it
didn't address the actual question. I honestly understand
the impulse to be annoyed with people who post vague,
unanswerable questions, but if you are going to appoint
yourself as the newsgroup sheriff so you can run those
people out of town, you should pay attention to what
questions are actually being asked.

Or was your point simply that beginners are not welcome here?

Barry

Subject: Re: Newbie optimization problem

From: D. Ismay

Date: 19 Mar, 2008 20:55:03

Message: 10 of 12

Barry wrote on 17-Mar-08 08:59 :
[...]
> D., I only gave this preface to let people know
<slap>

"Say what you mean, mean what you say."

Subject: Re: Newbie optimization problem

From: Thomas Clark

Date: 20 Mar, 2008 17:29:02

Message: 11 of 12

Barry,

Welcome to MATLAB. From the sounds of your post, your work
involves topics which MATLAB is greatly suited for. I almost
guarantee that in a year's time you'll have stopped using
excel for anything other than basic accounting.

Kudos for getting it (excel) to optimise on linear algebra
problems though!

Don't worry about being a newbie. I'm an experienced MATLAB
user - but am just getting into a different C++ application
too, so know what you're going through. It's SO hard to
learn a language at the same time as trying to solve a
specific problem.

As for optimisation, I'm not really up on linear algebra
either, but I do have a very well commented set of functions
to perform an optimisation. It should guide you quite well
through the use of functions like fminsearch. I imagine my
application was quite different to yours, but as a tool to
learn about program structure, it's pretty good.

I don't want to post it on the FEX as I've sold it in the
past, and it wouldn't feel ethical... However, if you email me:
t,clarkato2,co,uk (replace 'at' with '@' and commas with dots)
I'll supply you with a copy.

Cheers

Tom Clark

Subject: Re: Newbie optimization problem

From: zaman

Date: 21 Mar, 2008 09:10:16

Message: 12 of 12

Barry

Pls keep putting some more interesting questions.
We are here to share , to learn and to cooperate.
-zaman-

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
optimization Amir 16 Mar, 2008 14:05:12
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

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.
Related Topics