Bisection method using ode23

4 vues (au cours des 30 derniers jours)
Francesca Sbarbati
Francesca Sbarbati le 21 Oct 2021
Hi! I must use the shooting method by using bisection method to find root of f(s).
When I put "[x,u]= nlshoot1(10,0,2,0.01);" in the command window to verify the efficience, I get some errors.
I've tried as follows:
function [x,u]= nlshoot1(N,a0,b0,tol)
epi=exp(pi);
ak=a0;
bk=b0;
sk=(ak+bk)/2;
h=pi/N;
x=0:h:pi;
[xx,uv]= ode23(@fun,x,[ak 2*ak]);
fak=uv(N+1,1)-epi;
[xx,uv]= ode23(@fun,x,[bk 2*bk]);
fbk=uv(N+1,1)-epi;
[xx,uv]= ode23(@fun,x,[sk 2*sk]);
fk=uv(N+1,1)-epi;
afk=abs(fk);
while afk>=tol
if fak*fbk<0
sk=(ak+bk)/2;
[xx,uv]= ode23(@fun,x,[sk 2*sk]);
fk=uv(N+1,1)-epi;
if fk==0
%I have a root
else
if fk*fak<0
bk=sk;
else
ak=sk;
[xx,uv]= ode23(@fun,x,[sk 2*sk]);
fk=uv(N+1,1)-epi;
end
end
else
end
afk=abs(fk);
end
u=uv(:,1);
end
function uvp= fun(x,uv)
uvp=[uv(2); (exp(-x)/2*(uv(2)^2+uv(1)^2))-(exp(-x)/2+cos(x)+2*sin(x))];
%u is the first component and v is the second component
end

Réponses (1)

Francesca Sbarbati
Francesca Sbarbati le 22 Oct 2021
I solve this problem choosing a good value of a0 and b0.
I write in the Command window the following commands:
[x,u]= nlshoot1(10,0,1.01,0.001);
y=exp(x)+sin(x); %to compare the solution
plot(x,u,'r*',x,y,'k-')

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by