Using the shooting method with ode45 and lagr

Im getting an error while trying to apply the shooting method and I cant get it to work if someone could help
Here is the main part of the code:
clc
clear all
close all
m = 1;
K = 1;
B=0.5;
y0=2.0;
v0=0;
tfin=70;
h=0.01;
t=0:h:tfin;
y(1)=y0;
v(1)=v0;
Amp=-2;
u=[2.5 2.6]
tol_shot=1e-10;
reltol=3e-14;
abstol=1e-13;
abstol_1=abstol;
abstol_2=abstol;
options=odeset('RelTol',reltol,'AbsTol',[abstol_1 abstol_2]);
i=1;
dif=1;
while tol_shot< dif
f1=@(T,YV) [YV(2);(u(i)*(1-YV(2)^2)*YV(2) - K*(B*YV(1)^2))/m];
[t,yv]=ode45(f1,t,[y0,v0],options);
y=yv(:,1);
v=yv(:,2);
%------------ Shooting
ind=find(y==min(y),1);
aux=lagr(t(ind-1:ind+1),-y(ind-1:ind+1)); % lagr is a lagrange function, input coodenates in wich we want to find the max, output ind of the max point
Aneg(i)=-aux(2);
dif=abs(Aneg(i)-Amp);
if i>1
m=(Aneg(i)-Aneg(i-1))/(u(i)-u(i-1));
u(i+1)=u(i)-(Aneg(i)-Amp)/m;
end
plot(t,y)
title(['u=',num2str(u(i)), ' Amp neg=' ,num2str(Aneg(i))])
i=i+1;
clear y v aux ind aneg
end
u(end-1)
the error im getting is this one:
Warning: Failure at t=1.620779e-01. Unable to meet integration tolerances without reducing the step size below the smallest value
allowed (4.440892e-16) at time t.
> In ode45 (line 360)
In shooting (line 39)
Array indices must be positive integers or logical values.
Error in shooting (line 49)
aux=lagr(t(ind-1:ind+1),-y(ind-1:ind+1));

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 27 May 2020

Edited:

on 27 May 2020

Community Treasure Hunt

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

Start Hunting!