how is it possible to give res-function in bvp4c only values of the beginning of the interval ?
2 views (last 30 days)
Show older comments
Hi
I'm trying to use a boundary value problem in a loop to solve the problem in a piecewise manner in some intervals as [ya yb]. to best of my knowledge bvp should be given value of ya for y1 and yb for y2 or vice versa.
However this is is not suit my problem, as it can be seen in the figure.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1113050/image.png)
In each iteration I set ya(2) as the last value of pervious iteration (y2(end) or yy20)). To get resonable results I should set ya(1) as the last value of pervious iteration (y1(end) or yy10)), but this give me compeletly wrong answer.
how can I set simultaneously ya(1) = yy10 and ya(2) = yy20?
Thank you so, so much in advance! I would deeply appreciate the help.
clear all
global a1 yy10 yy20 b1 tauf
tf = 150; dt = 1; a1 = 0.08;b1 = 1;tauf = 8e4;tn = 150;tm = 15;
yy20 = 0; yy10 =0;
for j = tm:tm:tn
dl = (tm)/dt;
Tl = linspace(j-tm,j,dl); %each step samples
solinit = bvpinit(Tl, [1 1]);
options = bvpset('Stats','on','RelTol',5e-1);%,'NMax',1000
%%--------------------
% ODE's for states and costates
sol1 = bvp4c(@BVP_ode, @BVP_bc, solinit, options);
t = sol1.x ;
y = sol1.y;
y1 = -y(1,:);
y2 = -y(2,:);
yy10 = y(1,end);
yy20 = y(2,end);
pb = ((y2) / b1);
pd =Dl(t)';
figure (101);
subplot(2,1,1);plot(t,y1);hold on;ylabel('y1')
subplot(2,1,2);plot(t,pb);hold on;ylabel('y2')
end
%% -------------------------
function dydt = BVP_ode(t,y)
global a1 b1 yy10 tauf ;
ut1 = -(y(2,:)) / (b1);
dydt = [((-y(1,:)-yy10)/tauf) + ((ut1 - Dl(t)))
-((y(2,:)-0)/tauf) - (a1*(y(1,:) - yy10)) ];
end
% -----------------------------------------------
% The boundary conditions:
function res = BVP_bc(ya,yb)
global yy20 yy10
res = [ yb(1,:)- yy10
ya(2,:)- yy20];
end
%-----------------------------------------------
function d = Dl(t)
d = DFTP75(t)'/1000;
end
function d4 = DFTP75(t)
dddd = load ( 'FTP751.mat');
ddd = dddd.FTP75(:,2);
dd = 1.3*ddd';
tt3 = 0:1:2475-1;
d4 = interp1(tt3,dd,t);
end
8 Comments
Torsten
on 31 Aug 2022
Edited: Torsten
on 31 Aug 2022
If this is the problem, you should solve it over the complete interval. A step-by-step solution over subintervals is possible, but you must adopt your boundary condition ya(1) depending on what you get for yb(1) in the step-by-step solution and recalculate. In principle, this would be the shooting approach to solve boundary value problems.
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!