find the root of a function in an interval

6 vues (au cours des 30 derniers jours)
xueqi
xueqi le 24 Oct 2013
Commenté : dpb le 25 Oct 2013
Hi fellows,
I would like to solve an expontential function f in an interval, say, [0,e]. I try to use solve but it is very slow. Then I try to use fzero .It is faster but still not efficient enough. As I want the solution to be in the interval, I think it should be more efficient if I can specifiy the interval. Luckily fzeros allows me to do so. But meanwhile it requires the value of function f changes sign in the boundadry of the interval. I can not guarantee f(0) has a different sign as f(e) so fzero is not working...Could you give me some advice about this? Here is an example of the code
if true
%
r=0.01;
D=[0.1,-0.5,-0.4;-0.6,0.2,0.5];
P=[0.2,0.2,0.6];
d11=D(1,1);
d12=D(1,2);
d13=D(1,3);
p1=P(1);
p2=P(2);
p3=P(3);
e=100;
f=@(x) p1*d11*exp(-r*x*d11)+p2*d12*exp(-r*x*d12)+p3*d13*exp(-r*x*d13);
x=fzero(f,[0,100])
end
and I get the error messages is
if true
% Error using fzero (line 274)
The function values at the interval endpoints must differ in sign.
end
  5 commentaires
xueqi
xueqi le 25 Oct 2013
Hi, Thanks for your reply. I actually did make a mistake specifying D. Now it is possible for f to be negative. But what I really want to is find a general way to do this. As I have a set of D that need to be calculated, I am unable to analyze them individually.
dpb
dpb le 25 Oct 2013
A set of "D" that need to be calculated???? You've given D as a set of constants.
You need to sit down with pencil and paper and look at what you get for limiting conditions from your set of constants -- or plot it and visualize it. The system is not at all like you think methinks...
Try
>> P=[0.2,0.2,0.6];
>> D=[0.1,-0.5,-0.4];
>> r=0.01;
>> rD=r*D;
>> f=@(x) P.*D.*exp(-rD.*x);
>> x=[-100:100]';
>> y=cell2mat(arrayfun(f,x,'uniformoutput',false));
>> plot(x,[y sum(y,2)])
>>

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by