Bisection method using ode23

조회 수: 4 (최근 30일)
Francesca Sbarbati
Francesca Sbarbati 2021년 10월 21일
답변: Francesca Sbarbati 2021년 10월 22일
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

답변 (1개)

Francesca Sbarbati
Francesca Sbarbati 2021년 10월 22일
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-')

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by