Path: news.mathworks.com!not-for-mail
From: "deva " <andadodk@yahoo.fr>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Solving an equation with no close analytical solution
Date: Sat, 20 Dec 2008 10:35:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 61
Message-ID: <giihon$t6b$1@fred.mathworks.com>
References: <gifvtb$6tp$1@fred.mathworks.com> <gigbvi$pfg$1@fred.mathworks.com>
Reply-To: "deva " <andadodk@yahoo.fr>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1229769303 29899 172.30.248.37 (20 Dec 2008 10:35:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 20 Dec 2008 10:35:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1646150
Xref: news.mathworks.com comp.soft-sys.matlab:508109

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gigbvi$pfg$1@fred.mathworks.com>...
> "deva " <andadodk@yahoo.fr> wrote in message <gifvtb$6tp$1@fred.mathworks.com>...
> > Hi to all and thanks in advance for your help.
> > I have to solve an equation that writes as 
> > a=exp(x*c)*(exp((b-x)*c)-1)/(b-x)
> > The unknown is x while a,b and c are known
> > I have 5000 values for a while c and b are the same through each equation, this means that I need to find 5000 x.
> > In maple I can find a numerical solution with fsolve, but I have to do manually for each of the 5000 values (which takes a awful amount of time)
> > I would like to know if there is a way to find a numerical solution to this equation in matlab and to this in a loop that allows to use the array of 5000 values of a to create an array for the 5000 values of x.
> > 
> > I do know if that's clear, i have been struggling for this porblem for the latest three days.
> > So any help would be really greatly appreciated!!!
> > thanks again
> > a
> 
> The simple answer is a loop using fzero, not fsolve.
> Fzero will be more robust for problems of one variable,
> if you are able to bracket the root.
> 
> The more complex answer is to use arrayfun, which
> will solve the problem using an implicit loop. Still use
> fzero though.
> 
> My next choice as an answer is to solve it as a batched
> problem in fsolve. Use the largescale method. Specify
> the pattern of the jacobian matrix through optimset.
> I discuss this style of solution in my optimization tips
> and tricks.
> 
> http://www.mathworks.com/matlabcentral/fileexchange/8553
> 
> You may need to verify the solutions for convergence,
> since some subproblems may possibly diverge. Go back
> and apply fzero to those subproblems only.
> 
> HTH,
> John

Hi John,
thanks a lot for your message.
I have tried and I get the message
"??? Error using ==> fzero
FZERO cannot continue because user supplied function_handle ==> @(x) myfun(x,a,b,c)
failed with the error below.

Error: File: myfun.m Line: 5 Column: 1
Function definitions are not permitted at the prompt or in scripts. "

What I have done is 
function l=myfun(x,a,b,c)
l=(c-(exp(x*a).*(exp((b-x)*a)-1))/(b-x));

a=540;
b=(1+0.02)^(1/12)-1;
c=5007;

 fzero(@(x) myfun(x,a,b,c),0.1);

thanks again