Multiple boundary conditions with two separate intervals

3 views (last 30 days)
Hi everyone,
I have the following BVP:
And that's my code:
function sol = OdeProblem()
xc=1;
xd=3;
xmesh = [0 0.25 0.5 0.75 xc xc xd xd 3.25 3.5 3.75 4];
solinit = bvpinit(xmesh,@guess);
sol = ode(@bvpfcn, @bcfcn, solinit);
function dydx = bvpfcn(x,y)
dydx = zeros(8,1);
dydx = [y(2)
-4 .* y(2)
y(4)
-4 .* y(4)
y(6)
-4 .* y(6)
y(8)
-4.* y(8)];
end
function res = bcfcn(ya,yb)
res = [ya(1,1)-2
ya(2,2)-ya(1,2)-yb(5,2)
ya(3,1)-1
ya(4,2)-ya(3,2)-yb(7,2)
ya(5,3)-5
ya(6,2)-ya(1,2)-yb(5,2)
yb(7,3)-0.5
yb(8,1)-ya(3,2)-yb(7,2)];
end
function g = guess(x)
g = [sin(x)
cos(x)
sin(x)
cos(x)
sin(x)
cos(x)
sin(x)
cos(x)];
end
end
I am having trouble running the code :( The error is:
Error using Test/guess
Too many input arguments.
Error in bvpinit (line 102)
w = feval(v,x(1),1,extraArgs{:}); % check region 1, only.
Error in Test (line 8)
solinit = bvpinit(xmesh,@guess);
Could someone help me? I would be very grateful! Thanks a lot! :) Have a nice day!

Answers (1)

Torsten
Torsten on 1 Dec 2022
Edited: Torsten on 1 Dec 2022
To use bvp4c, the two intervals have to be connected. Thus in your case, it's not applicable (or only with big effort).
syms y1(x) y2(x) y3(x) y4(x)
syms C11 C12 C21 C22 C31 C32 C41 C42
eqn1 = diff(y1,x,2) + 4*diff(y1,x) == 0;
eqn2 = diff(y2,x,2) + 4*diff(y2,x) == 0;
eqn3 = diff(y3,x,2) + 4*diff(y3,x) == 0;
eqn4 = diff(y4,x,2) + 4*diff(y4,x) == 0;
y1(x) = dsolve(eqn1);
vary1 = symvar(y1);
y1 = subs(y1,[vary1(2),vary1(3)],[C11 C12]);
dy1 = diff(y1,x);
y2(x) = dsolve(eqn2);
vary2 = symvar(y2);
y2 = subs(y2,[vary2(2),vary2(3)],[C21 C22]);
dy2 = diff(y2,x);
y3(x) = dsolve(eqn3);
vary3 = symvar(y3);
y3 = subs(y3,[vary3(2),vary3(3)],[C31 C32]);
dy3 = diff(y3,x);
y4(x) = dsolve(eqn4);
vary4 = symvar(y4);
y4 = subs(y4,[vary4(2),vary4(3)],[C41 C42]);
dy4 = diff(y4,x);
eqalg1 = y1(0)-2==0;
eqalg2 = dy1(1)-y1(1)-y3(3)==0;
eqalg3 = y2(0)-1==0;
eqalg4 = dy2(1)-y2(1)-y4(3)==0;
eqalg5 = y3(4)-5==0;
eqalg6 = dy3(3)-y1(1)-y3(3)==0;
eqalg7 = y4(4)-0.5==0;
eqalg8 = dy4(3)-y2(1)-y4(3)==0;
[C_11 C_12 C_21 C_22 C_31 C_32 C_41 C_42] = solve([eqalg1,eqalg2,eqalg3,eqalg4,eqalg5,eqalg6,eqalg7,eqalg8],[C11 C12 C21 C22 C31 C32 C41 C42]);
y1 = subs(y1,[C11 C12],[C_11 C_12])
y1(x) = 
y2 = subs(y2,[C21 C22],[C_21 C_22])
y2(x) = 
y3 = subs(y3,[C31 C32],[C_31 C_32])
y3(x) = 
y4 = subs(y4,[C41 C42],[C_41 C_42])
y4(x) = 
hold on
fplot(y1,[0 1])
fplot(y2,[0 1])
fplot(y3,[3 4])
fplot(y4,[3 4])
hold off
grid on

Community Treasure Hunt

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

Start Hunting!

Translated by