Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Making two functions equal
Date: Wed, 6 Jul 2011 06:33:10 +0000 (UTC)
Organization: IITK
Lines: 57
Message-ID: <iv0vj6$rlf$1@newscl01ah.mathworks.com>
References: <iuqiu9$mdj$1@newscl01ah.mathworks.com> <iuqojk$69r$1@newscl01ah.mathworks.com> <iuvs91$19b$1@newscl01ah.mathworks.com> <iv00l3$d2b$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1309933990 28335 172.30.248.35 (6 Jul 2011 06:33:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 6 Jul 2011 06:33:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2795384
Xref: news.mathworks.com comp.soft-sys.matlab:735043

Dear Sir,

Thanks for your reply. I am getting a NAN value when run the programme. But I am getting the answer for the same input when I did using bisection method. But it is consuming much of my time. Is there any way to solve this? my input was q=0.2;
Regards,
Reshma
"Steven_Lord" <slord@mathworks.com> wrote in message <iv00l3$d2b$1@newscl01ah.mathworks.com>...
> 
> 
> "Reshma B" <rbmindworking@gmail.com> wrote in message 
> news:iuvs91$19b$1@newscl01ah.mathworks.com...
> > Dear Sir,
> >
> > Thank you very much for your reply. I tried to solve the problem using 
> > fzero. I am not familiar with using fzero. Could you please tell me the 
> > problem?
> > q=input('Enter q');
> > Ke=0.01;
> > S3=r_nl_3layers_noG_equi_fn_noinput(q);
> > S1 = r_nonlinear_1layer_noG_equi_fn_noinput(q,Ke); b = abs(S3-S1); 
> > Ke=fzero('b',Ke,optimset('TolX',1e-15));
> 
> Create a function that accepts an input, evaluates your two functions for 
> that input, and returns their difference. Then call FZERO on _that_ 
> function.
> 
> 
> % Begin subtractTheTwoFunctions.m
> function thedifference = subtractTheTwoFunctions(q, Ke)
> valueOfFirstFunction = r_nl_3layers_noG_equi_fn_noinput(q);
> valueOfSecondFunction = r_nonlinear_1layer_noG_equi_fn_noinput(q,Ke);
> thedifference = valueOfFirstFunction -valueOfSecondFunction;
> % End subtractTheTwoFunctions.m
> 
> 
> % Paste the following into the Command Window once you've created the 
> function above
> Ke = 0.01;
> initialGuess = 0.5;
> options = optimset('TolX', 1e-8);
> parameterValue = fzero(@(p) subtractTheTwoFunctions(p, Ke), initialGuess, 
> options);
> 
> % To check, compute the value of each function for the parameterValue 
> returned by FZERO:
> valueOfFirstAtParameter = r_nl_3layers_noG_equi_fn_noinput(parameterValue);
> valueOfSecondAtParameter = 
> r_nonlinear_1layer_noG_equi_fn_noinput(parameterValue, 0.01);
> 
> % Now subtract the function values. The difference should be small.
> differenceAtParameter = valueOfFirstAtParameter-valueOfSecondAtParameter
> 
> 
> -- 
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on 
> http://www.mathworks.com