Bisection method using ode23
Afficher commentaires plus anciens
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
le 22 Oct 2021
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!