Thread Subject: solving equation

Subject: solving equation

From: Kishore

Date: 4 Mar, 2009 17:27:01

Message: 1 of 4

Hello,

I need to solve the following equation

' m + k*(1-log(k)) = 0 '

the value of m is known.

I tried the following

declare k as a symbol. i,e syms k,
then, declare the equation eq = '' m + k*(1-log(k)) = 0 ';

then use solve ( eq);

But it just returns the plain expression -k+k*log(k),

i want the value of k for which this equation is optimum .

if i use roots(func) it gives an error

??? Error using ==> zeros
Trailing string input must be a valid numeric class name.

Error in ==> roots at 23
r = zeros(0,1,class(c));

Am i missing something.

Thanks.

Subject: solving equation

From: Alan Weiss

Date: 4 Mar, 2009 17:39:30

Message: 2 of 4

doc fzero

You cannot solve this problem for every value of m; k - k*log(k) has a
maximum value of 1 at k = 1, and so there are two values of k that solve
the equation for 0 < m < 1. For 0 < m < 1 I recommend you start fzero
with the values [m/2,1] or [1,e].

Alan Weiss
MATLAB mathematical toolbox documentation

Kishore wrote:
> Hello,
>
> I need to solve the following equation
>
> ' m + k*(1-log(k)) = 0 '
>
> the value of m is known.
>
> I tried the following
>
> declare k as a symbol. i,e syms k,
> then, declare the equation eq = '' m + k*(1-log(k)) = 0 ';
>
> then use solve ( eq);
>
> But it just returns the plain expression -k+k*log(k),
>
> i want the value of k for which this equation is optimum .
>
> if i use roots(func) it gives an error
>
> ??? Error using ==> zeros
> Trailing string input must be a valid numeric class name.
>
> Error in ==> roots at 23
> r = zeros(0,1,class(c));
>
> Am i missing something.
>
> Thanks.

Subject: solving equation

From: Steven Lord

Date: 4 Mar, 2009 18:05:44

Message: 3 of 4


"Kishore " <kishore3385@yahoo.co.in> wrote in message
news:gomdl5$h8h$1@fred.mathworks.com...
> Hello,
>
> I need to solve the following equation
>
> ' m + k*(1-log(k)) = 0 '
>
> the value of m is known.
>
> I tried the following
>
> declare k as a symbol. i,e syms k,
> then, declare the equation eq = '' m + k*(1-log(k)) = 0 ';
>
> then use solve ( eq);
>
> But it just returns the plain expression -k+k*log(k),

This is solving the question you asked, not the question you wanted
answered.

When you call SOLVE with just an equation, it has to figure out for which
variables you want to solve. In this case, it solved for m in terms of k.
In order to solve for k given a specific value of m, you need to do
something a little different.


syms k
m = 0.5;
equation = m + k*(1-log(k));
solution = solve(equation, k)
doubleSolution = double(solution)
check = subs(equation, k, doubleSolution)


Or you can solve the equation numerically with FZERO as Alan suggested.

*snip*

--
Steve Lord
slord@mathworks.com

Subject: solving equation

From: Kishore

Date: 4 Mar, 2009 19:21:02

Message: 4 of 4

Hello Steven,

Thanks a lot.
Actually i had given the value of m,
what i had not done was giving the variable name k in solve(),

Thanks Steven and Alan for the reply.

"Steven Lord" <slord@mathworks.com> wrote in message <gomftp$o1d$1@fred.mathworks.com>...
>
> "Kishore " <kishore3385@yahoo.co.in> wrote in message
> news:gomdl5$h8h$1@fred.mathworks.com...
> > Hello,
> >
> > I need to solve the following equation
> >
> > ' m + k*(1-log(k)) = 0 '
> >
> > the value of m is known.
> >
> > I tried the following
> >
> > declare k as a symbol. i,e syms k,
> > then, declare the equation eq = '' m + k*(1-log(k)) = 0 ';
> >
> > then use solve ( eq);
> >
> > But it just returns the plain expression -k+k*log(k),
>
> This is solving the question you asked, not the question you wanted
> answered.
>
> When you call SOLVE with just an equation, it has to figure out for which
> variables you want to solve. In this case, it solved for m in terms of k.
> In order to solve for k given a specific value of m, you need to do
> something a little different.
>
>
> syms k
> m = 0.5;
> equation = m + k*(1-log(k));
> solution = solve(equation, k)
> doubleSolution = double(solution)
> check = subs(equation, k, doubleSolution)
>
>
> Or you can solve the equation numerically with FZERO as Alan suggested.
>
> *snip*
>
> --
> Steve Lord
> slord@mathworks.com
>

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

Contact us at files@mathworks.com